help with for statement

8 vues (au cours des 30 derniers jours)
son
son le 20 Août 2014
Commenté : Image Analyst le 30 Mai 2021
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

Réponses (2)

Ben11
Ben11 le 20 Août 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

Edmund Williams
Edmund Williams le 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 commentaire
Image Analyst
Image Analyst le 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
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Introduction to Installation and Licensing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by