Greater than operator not working in if statement

7 ビュー (過去 30 日間)
Jacob Huhtala
Jacob Huhtala 2020 年 9 月 23 日
コメント済み: Jacob Huhtala 2020 年 9 月 23 日
Here is my code, POLY60estra is a 1000x1 vector. here is the lines of code
for p=1:500
if (POLY60estra(p,1) > 0) && (POLY60estra(p,1) <= 7.1)
POLY60estra2(p,1) = POLYestra(p,1);
POLY60estre2(p,1) = POLYestre(p,1);
end
end
Thank you for any help ahead of time.
  3 件のコメント
the cyclist
the cyclist 2020 年 9 月 23 日
I assure you that the greater than operation is working. It's just not doing what you expect.
Please do two things to help us help you:
  • Upload the variable POLY60estra in a MAT file, using the paperclip icon from the INSERT tools
  • Be more specific when you say, "not working". Does the code crash? Does it give an answer you do not expect? Is the code going into the if statement when you don't expect it to?
Be specific about what you see as the problem, so that we can be specific in helping you solve it.
Jacob Huhtala
Jacob Huhtala 2020 年 9 月 23 日
The code crashes when its ran, giving me the error code,
"Undefined operator '>' for input arguments of type 'table'.
Error in StressStrainLab (line 88)
if (POLY60estra(p,1) > 0) && (POLY60estra(p,1) <= 7.1)"

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

回答 (1 件)

David Hill
David Hill 2020 年 9 月 23 日
編集済み: David Hill 2020 年 9 月 23 日
No need for loop.
idx=(POLY60estra(1:500)>0&POLY60estra(1:500)<=7.1);
POLY60estra2(idx)=POLYestra(idx);
POLY60estre2(idx)=POLYestre(idx);
  3 件のコメント
David Hill
David Hill 2020 年 9 月 23 日
編集済み: David Hill 2020 年 9 月 23 日
What is POLYestre? Below works for your file POLY60estra
a=POLY60estra.strain60ep;
idx=(a(1:500)>0&a(1:500)<=7.1);
POLY60estra2(idx)=a(idx);
Jacob Huhtala
Jacob Huhtala 2020 年 9 月 23 日
That actually got it to work properly. Thank you

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

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by