Why are these two variables not the same value?

I think I'm going crazy because I have two differently named variables both set equal to the same thing but they are returning different values. These are the variables:
Max.H1_E_RT_Moment_Max = max(abs(E.RT_Moment_Y_Ave));
Max.H2_E_RT_Moment_Max_Y = max(abs(E.RT_Moment_Y_Ave));
These are the returned values:
Max.H1_E_RT_Moment_Max = 57.7207
Max.H2_E_RT_Moment_Max_Y = 21.0916
Is there any reason why this might be happening?

5 个评论

Sounds like E or E.RT_Moment_Y_Ave are changing in between the two calls.
By the way, could you confirm that E is a scalar struct? Or is this object-oriented work in which case RT_Moment_Y_Ave could potentially be a method ?
I don't know how it could be changing because the two variables are defined one line after the other (lines 1732 and 1733).
And yes, E is a 1x1 struct.
RT_Moment_Y_Ave is defined as a 101x1 double.
What I find even stranger is that the value 21.0916 doesn't even show up in the 101 array but the value 57.7207 does.
I really only need the 57.7207 value to put into a table for an assignment. I'm just concerned as to why it gives a different value
Is it practical to post the code and any relevant data, so we can test?
Sure sure. Here's a google drive link with the files I've been using. https://drive.google.com/drive/folders/1w1taoyXov3IhRKbWZu-Ig6pvAtlpwMGi?usp=sharing
Let me know if it doesn't work.

请先登录,再进行评论。

 采纳的回答

15 lines further down you have
Max.H2_E_RT_Moment_Max_Y = max(abs(E.RT_Moment_Z_Ave));
which overwrites the previous value.

1 个评论

Oh my god, I'm so stupid sorry. I've done way too much copying and pasting and must have just overlooked it. So sorry to waste your time

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Variables 的更多信息

产品

版本

R2022b

标签

Community Treasure Hunt

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

Start Hunting!

Translated by