Subscripted assignment dimension mismatch.Error in fnc (line 12) matrix1(1,​1)=cos(k*d​elta_z);ma​trix1(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..

채택된 답변

Michelangelo Ricciulli
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개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by