Subscripted assignment dimension mismatch.Error in fnc (line 12) matrix1(1,1)=cos(k*delta_z);matrix1(1,2)=(i/q)*sin(k*delta_z);
1 次查看(过去 30 天)
显示 更早的评论
i tried to form an matrice and took this error. here is my code.
function [matrix1,matrix2] = fnc(delta_z,w);
delta_z=450e-9;
N_a=2.5;
f=3e14:1e12:5e14;
w=2*pi*f;
k=N_a*(w/3e8);
q_j=-k/(2*pi*f*4*pi*10e-7);
matrix1(1,1)=cos(k*delta_z);matrix1(1,2)=(i/q)*sin(k*delta_z);
matrix2(1,1)=(i*q)*sin(k*delta_z);;matrix2(1,2)=cos(k*delta_z);
end
my aim is to form a matrix like the one in an image and for different layers and multiply them with another matrices. do you suggest any thing? best regards..
0 个评论
采纳的回答
Michelangelo Ricciulli
2018-3-31
Hi, Before answering the question, I want to give you a couple of suggestions.
First, try to post your code in better format. It is really hard to read (put the code in "code" style, and try to use one instruction per row).
Second, if you try your code one instruction at a time, it's much easier to find where the error is located. Or, even better, put your code in a script/function file and then try to execute it. Matlab will give you details about where the error is found. (Error in eren_baris (line 7) k=N_a(w/3e8);)
Let's answer your question now. You wrote
k=N_a(w/3e8);
but probably, you wanted
k=N_a*(w/3e8);
Without the multiplication, matlab is interpreting w/3e8 as an index for N_a. But w/3e8 is not an integer, and thus can't be an index. Moreover, in this case, N_a is not even a vector.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!