フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

So i Know how logical indexing is converted to loops, however this one gets me. Could some one please help!!

1 回表示 (過去 30 日間)
Zachary Holmes
Zachary Holmes 2015 年 12 月 4 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
So the Question is: Write MATLAB code using an iterative (or programming) approach to repli- cate the calculation done in the script above
A = [8,6.5, 4,7,3.510];
A(A < 7) = A(A < 7) * 1.1;
and My solution which is wrong is:
A=input('Enter an array ', 's');
for i=length(A)
if A(i)<7
A(i)=A(i)*1.1
end
end
disp())
Thanks
  1 件のコメント
Torsten
Torsten 2015 年 12 月 4 日
for i=1:length(A)
if A(i)<7
A(i)=A(i)*1.1;
end
end
Best wishes
Torsten.

回答 (1 件)

Jan
Jan 2015 年 12 月 4 日
The code contains several problems.
1. Why do you use input(., 's') to define the array as a string? Using this line is much better:
A = [8, 6.5, 4, 7, 3.510];
2. for i=length(A) runs a "loop" over one single element only. Loo in the documentation to see, that you need something like for i = a:b for a loop from a to b.
3. disp()) ?!

この質問は閉じられています。

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by