简体   繁体   English

该声明在MatLab中意味着什么

[英]What does this statement mean in MatLab

filename = 'SOMETHING';
eval(['load ' filename]);

eval(['load ' filename '_vid1'])
vid123=permute(vid,[2 1 3]);
size(vid)

eval(['load ' filename '_vid2'])
vid123(:,:,(size(vid123,3)+1):(size(vid123,3)+size(vid,3)))=permute(vid,[2 1 3]);
size(vid)

I know it has to do with loading a file and finding other files with the same name and '_vidX' appended to it, but what does line 7 exactly do/mean? 我知道它与加载文件并查找其他具有相同名称并附加了'_vidX'的文件有关,但是第7行到底是做什么/意味着什么?

Carrying on from Daniel's answer, your question is stemming from the fact that you don't quite know how permute works. 从丹尼尔的答案继续进行,您的问题源于您不太了解permute工作原理。 The goal of permute is to rearrange the dimensions of a matrix but leave the size of the matrix intact. permute的目的是重新排列矩阵的尺寸,但保持矩阵的大小不变。 You specify the matrix you want to "permute" as well as a vector that tells you which input dimensions map to the output. 您可以指定要“置换”的矩阵以及一个向量,该向量可以告诉您哪些输入维映射到输出。

What permute(vid, [2 1 3]); 什么permute(vid, [2 1 3]); means is that the second dimension of the input goes to the first dimension of the output. 意思是输入的第二维转到输出的第一维。 The first dimension of the input goes to the second dimension of the input, and the third dimension stays the same. 输入的第一维转到输入的第二维,而第三维保持不变。 The effect of this is that vid is a 3D matrix where each 2D slice /frame is transposed while maintaining the same amount of slices / frames in the final output. 这样的效果是, vid是一个3D矩阵,其中每个2D切片/帧都进行了转置,同时在最终输出中保持相同数量的切片/帧。 You are swapping the second and first dimensions which is essentially what the transpose does. 您正在交换第二维和第一维,这实际上是转置所做的。

Therefore, the first load statement loads in your frames through the variable vid , and vid123 originally has some number of frames where each frame is transposed - these correspond to the first video. 因此,第一个load语句通过变量vid将帧加载到您的帧中,并且vid123最初具有一定数量的帧,每个帧都在其中转置-这些对应于第一个视频。 After this, you are loading in the second video where vid gets overwritten with the frames from the second video. 之后,您将加载第二个视频,其中vid被第二个视频中的帧覆盖。 You then add those frames on top of vid123 . 然后,将这些帧添加到vid123 Therefore, you are simply piecing the frames from the first frame and second frame together - transposed creating one larger video. 因此,您只需将第一帧和第二帧中的帧拼接在一起-换位即可创建一个更大的视频。

I would highly recommend you resave this so that both videos are separated clearly by different variables, or perhaps have a structure that contains both of the videos together. 我强烈建议您重新保存此视频,以使两个视频都可以通过不同的变量清楚地分开,或者可能具有同时包含两个视频的结构。 Having the variable vid being stored in two separate files is problematic. 将变量vid存储在两个单独的文件中是有问题的。

Something like this would work: 这样的事情会起作用:

load([filename '_vid1']);
vid1 = vid;
load([filename '_vid2']);
vid2 = vid;
clear vid;
save videos;

... or even this would work: ...甚至可以这样工作:

load([filename '_vid1']);
s.vid1 = vid;
load([filename '_vid2']);
s.vid2 = vid;
clear vid;   
save videos;

In the first version, both videos are stored in separate variables vid1 and vid2 and the second version, both videos are saved in one structure. 在第一个版本中,两个视频均存储在单独的变量vid1vid2而在第二个版本中,两个视频均存储在一个结构中。

Just to rewrite the 7th line how it should be rewritten: 只是重写第七行,应该如何重写:

vid123=cat(3,vid123,permute(vid,[2 1 3])

It concatenates both variables among the 3rd dimension. 它在第三个维度中将两个变量连接在一起。 In case you intend to understand the original line, just put the end statement wherever it should be used and it is suddenly much more readable: 如果您想了解原始行,只需将end语句放在应该使用的地方,然后突然可读性强:

vid123(:,:,end+1:end+size(vid,3))=permute(vid,[2 1 3]);

Using end+1:end+size(vid,3) it inserts size(vid,3) -many new slices into the 3d matrix vid123 使用end+1:end+size(vid,3)可以将size(vid,3)许多新切片插入3d矩阵vid123

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM