Changing elements of an array by row and column using for loop?

2 ビュー (過去 30 日間)
Harvey Rael
Harvey Rael 2018 年 8 月 3 日
コメント済み: Harvey Rael 2018 年 8 月 3 日
Hi all,
So essentially I am trying to correct some acos mistakes in an 180x40 array. I want to run through each element of the array first by rows then by columns, but I am having trouble with error messages. I keep getting "Index in position 2 exceeds array bounds (must not exceed 1)."
My array of angles look like this.
psi_deg = 180x40;
alpha = diff(psi_deg)
for i = 1:length(alpha)
for j = 1:size(alpha)
if alpha(i,j)<0
transform_angle(i,j) = 360 - psi_deg %If the angle should be greater than 180 but it is displayed as less, display the greater version
else transform_angle(i,j) = psi_deg(i,j)
end
end
end
Any thoughts why I continually get this error? Best, Harvey

採用された回答

James Tursa
James Tursa 2018 年 8 月 3 日
You should probably be using size(alpha,1) and size(alpha,2) instead of length(alpha) and size(alpha) in your looping. And you need to index psi_deg. That being said, it is hard to advise if what you are doing makes sense without knowing your goal.
  1 件のコメント
Harvey Rael
Harvey Rael 2018 年 8 月 3 日
I'll try this.
As to the goal, my goal is to create an array of angle measurements and correct for the issue where acos has returned a value less than 180 where I know it should be more.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by