update vector data to start with a different value at specific point.
1 回表示 (過去 30 日間)
古いコメントを表示
Dear community, I'd like to ask your support to find a solution for below condition.
I have 6 vectors. time, CtTHiRes, HiResCalc, CtTgrdCalc, idx8 and TS_tClntEngOut
my goal is to calculate HiResCalc which it will have same values as CtTHiRes using CtTgrdCalc.
for ii = 2:N+1
if exist ('time')
HiResCalc(ii) = CtTgrdCalc(ii-1) + HiResCalc(ii-1);
end
I'm stuck trying to update HiResCalc.....
what I need to do is when idx8 = 0, HiResCalc should be updated and get whathever the valu is in TS_tClntEngOut, in this case the update happens at second 250 but it can be anyother time.
after HiResCalc is updated, calculation should continue as shonw in the script above but I don't know how to make it.....
for ia= 1:length(HiResCalc);
if idx8(ia) == 0
HiResCalc(ia,1) = TS_tClntEngOut(ia);
end
end
here is an image for your reffrence...
as before any feedback will be highly appreciated
3 件のコメント
Umar
2024 年 8 月 7 日
Hi @Rod,
No problem, glad to help. Please don’t forget to vote for @Rajanya. Also, if you encounter any issues, please don’t hesitate to reach out to us for further assistance. Good luck!
採用された回答
Rajanya
2024 年 8 月 7 日
As far as I understand, you are unable to update the value of the vector ‘HiResCalc’ at indices where idx8 becomes logical 0.
By importing all the vectors as provided and writing the same code as given, the desired output is being achieved as the drop in the red line is occurring as expected. I have tried the same on MATLAB R2024a and it seems to be working fine. Some speculations can be made regarding the unequal dimensions of each vector which could make the code go wrong if the iteration limits are not provided accordingly, in case of which, the desired output might not be obtained.
If the updated value needs to be used in the same equation,
HiResCalc(i) = CtTgrdCalc(ii-1) + HiResCalc(ii-1)
you may try removing the second loop as it breaks the requirement. The code may go like:
for ii = 2:N+1
if exist("time")
if idx8(ii) ~= 0
HiResCalc(ii) = CtTgrdCalc(ii-1) + HiResCalc(ii-1);
else
HiResCalc(ii) = TS_tClntEngOut(ii);
end
end
end
This will do the required updating as necessary and use those values to go on with the computation. Feel free to get back if any queries are there regarding this or if this is not the expected behaviour you want to achieve.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!