简体   繁体   English

Matlab的 下标分配尺寸不匹配

[英]matlab ??? Subscripted assignment dimension mismatch

how do I resolve the problem with the following. 我该如何解决以下问题。 I am trying to create vectors distvec and magvec by using it's x and y components (embedded in c and r) while appending the z dimiensions. 我试图通过附加x维度同时使用x和y分量(嵌入在c和r中)来创建向量distvec和magvec。

for pxRow = 1:h % fixed pixel row
 for pxCol = 1:w % fixed pixel column

 for r = 1:h % row of distant pixel
 for c = 1:w % column of distant pixel

 R(c,r) = sqrt((r-pxRow)^2 + (c-pxCol)^2);                               % pythagoras theorem to get distance to each pixel
 O(c,r) = sqrt(Ox(c,r).^2 + Oy(c,r).^2);                                 % orientation vector 
 If(c,r) = sqrt((dx(c,r)).^2 + (dy(c,r)).^2);                            % magnitude of current 
 Rxs(c,r) = R(c,r)./norm(R(c,r));                                        % unit vector from x to s                     
 dist(c,r) = Rxs(c,r)./R(c,r);
 mag(c,r) = O(c,r).*If(c,r);
 distvec(c,r) = [dist(c) dist(r) 0];
 magvec(c,r) = [mag(c) mag(r) 0];                      
 b(c,r) = cross(magvec,distvec);% b field = If(s)O(s) x Rxs/R.^2  BIOT SAVART LAW
 end
 end
 B(i) = {b}; % filling a cell array with results. read below

??? ??? Subscripted assignment dimension mismatch. 下标分配尺寸不匹配。

Thanks 谢谢

A subscripted assignment dimension mismatch usually means that the size of the array on the left and the array on the right do not match. 下标的分配维度不匹配通常意味着左侧数组的大小与右侧数组的大小不匹配。

Since you're doing so many array assignments, and we can't see how big the arrays are, it's very difficult to diagnose. 由于您要执行许多数组分配,而且我们看不到数组有多大,因此很难诊断。

What else does the error say? 该错误还说明了什么? Does it specify which line is the problem? 是否指定问题所在的那一行?

I'm concerned about these two lines: 我担心这两行:

distvec(c,r) = [dist(c) dist(r) 0];
magvec(c,r) = [mag(c) mag(r) 0];  

And this line 而这条线

B(i) = {b};

Check that the sizes of the left and right vectors are the same using the size function or similar. 使用大小函数或类似函数检查左向量和右向量的大小是否相同。

Before the for loops, add 在for循环之前,添加

size(distvec)
size(magvec)
size(B)
size(b)

distvec and magvec should both be 3D arrays. distvec和magvec都应为3D阵列。

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

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