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

1 vue (au cours des 30 derniers jours)
A-Rod
A-Rod le 6 Août 2024
Commenté : Umar le 7 Août 2024
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 commentaires
A-Rod
A-Rod le 7 Août 2024
Hello Umar.
thank you for taking time to read my question and your help, I will use Rajanya's answer
Umar
Umar le 7 Août 2024
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!

Connectez-vous pour commenter.

Réponse acceptée

Rajanya
Rajanya le 7 Août 2024
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.
  1 commentaire
A-Rod
A-Rod le 7 Août 2024
hello Rajanya.
this is exactly what I was looking for, I appreciate your help.
thank you!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by