help with for statement

1 回表示 (過去 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 Center および File ExchangeInstall Products についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by