help with for statement
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
hi, this is my code. first u insert the value of channels. It will create a pattern S. then i want to determine equation: 'Pfwmchannel(k)=S(k).* L.*m'
i use for statement but this is the error 'In an assignment A(I) = B, the number of elements in B and I must be the same.'
dlg_title = 'Insert Factor Value';
x1 = inputdlg('Enter number of channels:',dlg_title, [1 50]);
n = str2num(x1{:});
j = 1:n;
S = zeros(1,length(j));
if mod(n,2)==1
for k = 1:length(j)
if mod(j(k),2) == 0
S(k) = (n^2-1)/4 + n*j(k)/2 - j(k)^2/2 - n + j(k)/2;
else
S(k) = (n^2+1)/4 + n*j(k)/2 - j(k)^2/2 - n + j(k)/2;
end
end
else
for k = 1:length(j)
S(k) = n^2/4 + n*j(k)/2 - j(k)^2/2 - n + j(k)/2;
end
end
L=1:1:100;
m=(1000./L)-1;
Pfwm= exp(-alpha.*L);
for k = 1:length(j)
Pfwmchannel(k)=S(k).* Pfwm.*m
end
0 Kommentare
Antworten (2)
Ben11
am 20 Aug. 2014
Adding an index to Pfwm and m might do the trick; with an alpha of 0.5 (arbitrary value) it did not give an error when I tried it and it seems to make sense:
for k = 1:length(j)
Pfwmchannel(k)=S(k).* Pfwm(k).*m(k)
end
0 Kommentare
Edmund Williams
am 30 Mai 2021
Can someone please correct this codes for me
X=zeros(1,2,5) X(1)=1 For n= 2:25 P=cos(x(n-1)) end; p;
1 Kommentar
Image Analyst
am 30 Mai 2021
Not sure what "correct" means to you but at least this runs without error.
X = zeros(1, 25)
P = zeros(1, length(X) - 1);
X(1) = 1;
for n = 2 : length(X)
P(n - 1) = cos(X(n - 1));
end
P
Siehe auch
Kategorien
Mehr zu Introduction to Installation and Licensing 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!