help with for statement
1 view (last 30 days)
Show older comments
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 Comments
Answers (2)
Ben11
on 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 Comments
Edmund Williams
on 30 May 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 Comment
Image Analyst
on 30 May 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
See Also
Categories
Find more on Install Products in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!