Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

beginner question for .m conversion

2 visualizaciones (últimos 30 días)
Mohamed Ibrahim
Mohamed Ibrahim el 16 de Oct. de 2015
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
I am beginner at MATLAB, I need to convert small program from fortran code to m file I succeed to do that except one command i don't know how to conver it in m file. The command is: x=x+1 could you help me?

Respuestas (1)

Geoff Hayes
Geoff Hayes el 16 de Oct. de 2015
Mohamed - the code to increment a local variable by one would be the same in MATLAB. Just do
x = x + 1;
  2 comentarios
Mohamed Ibrahim
Mohamed Ibrahim el 16 de Oct. de 2015
i did not mean it i need to to make x(n+1)=x(n) +... each time step in simulation.
Geoff Hayes
Geoff Hayes el 16 de Oct. de 2015
So you have some sort of recurrence relation. If you know how many elements to iterate over, you could do something like
n = 42;
x = zeros(n,1);
x(1) = 2;
for k=2:n
x(k) = x(k-1) + somethingElse;
end
In the above, we size x to be n elements long. We initialize the first element of x to be some random (for this example) number, and then iterate from 2 to the end of x updating each element according to whatever equation you require (this is the somethingElse).

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by