help with for statement

조회 수: 3 (최근 30일)
son
son 2014년 8월 20일
댓글: Image Analyst 2021년 5월 30일
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

답변 (2개)

Ben11
Ben11 2014년 8월 20일
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

Edmund Williams
Edmund Williams 2021년 5월 30일
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
Image Analyst
Image Analyst 2021년 5월 30일
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
Since your "Answer" is not an answer to @son's 7 year old question, it you have further difficulties, you should start your own question so we don't but @son with emails about activity on his question.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by