update vector data to start with a different value at specific point.

3 次查看(过去 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 个评论
A-Rod
A-Rod 2024-8-7
Hello Umar.
thank you for taking time to read my question and your help, I will use Rajanya's answer
Umar
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
Rajanya 2024-8-7
Hi @A-Rod,
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 CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by