Filter löschen
Filter löschen

How can I increase vector size of the output from 7 x 7 double to 30 x 7 double i.e how can I make a for-loop to repeat 30 times?

1 Ansicht (letzte 30 Tage)
Hi all, How can I increase the size of the output vector of the attached m-file (EulerMethod.m) from 7 x 7 double to 30 x 7 double. I actually need each variable in y0 to have 30 rows, that is, I need the for-loop to repeat 30 times. How can I do that? The file also calls other m-files, namely, Hion.m, C_Bulk.m , odes.m and Parameters.m, which are also attached.
Kind Regards Dursman
  3 Kommentare
Dursman Mchabe
Dursman Mchabe am 9 Okt. 2018
Thanks a lot for the response, I have to quickly read/learn about Pad array or interpolation.
I think I am simply failing to make my loop to repeat 30 times.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 9 Okt. 2018
You don't.
You initialized y0 to a 1x7 and then transpose it so that it is 7x1.
In your loop you call odes, which returns a 7x1. You transpose that to 1x7, and multiply by your time step, getting a 1x7.
Now you add the 7x1 y0 to the 1x7. In all releases before r2016b that would be an error. In R2016b and later there is the equivalent of bsxfun, so the results of adding the two with different orientations is 7x7 which is the output size you get.
Perhaps you want to do something more like
y(end+1, :) = y(end, :) + odes().' * Delta
  1 Kommentar
Dursman Mchabe
Dursman Mchabe am 9 Okt. 2018
Thanks a lot for the response, I have to quickly read/learn about Pad array or interpolation.
I think I am simply failing to make my loop to repeat 30 times. I think wanted line 42 to be
y(end+1, :) = y(end, :) + odes().' * Delta
instead of
y = y0 + dydt' * Delt;
Thanks a lot once again Walter.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by