# 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 Ansicht (letzte 30 Tage)
eren baris alici am 31 Mär. 2018
Bearbeitet: eren baris alici am 31 Mär. 2018
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 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Michelangelo Ricciulli am 31 Mär. 2018
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);)
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 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Logical finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by