Borrar filtros
Borrar filtros

How to make M×N matrix in matlab function simulink

2 visualizaciones (últimos 30 días)
Rabe24
Rabe24 el 23 de Jun. de 2022
Comentada: Rabe24 el 24 de Jun. de 2022
I make this code in matlab function simulink.
I set a sampling time and a simulation time, 0.001s and 10.0s.
I wanted a parameter, p(10001×100)(time×H), whose 100 is a roop number.
However, the parameter p was (1000100×100). The row was also set 100 times, like a double loop.
How can i fix them in simulink?
Below is the code in matlab function simlink.
The paramater input is (10001×1).
function p = fcn(input)
H=100;
dh=0.1;
p=zeros(H);
for r=1:1:H
p(r)=r*dh;
end
end
  2 comentarios
dpb
dpb el 23 de Jun. de 2022
p=zeros(H);
creates a 2D array of zeros HxH. Is that what was intended/wanted?
Your function doesn't ever use the argument variable input?
The loop as written will execute 100 times and set the linear addressing element r (1:100) only; since MATLAB is column-storage major, that will set the first column of p and leave the other 99 as zeros.
That result could be more efficienty be code in MATLAB using array syntax as
function p = fcn(input)
H=100;
dh=0.1;
p=dh*[1:H];
end
which still doesn't use the argument variable so also is probably not what is intended.
It's not clear to me from the description the exact result wanted; can you use a much smaller size of arrays (say 10 elements or so instead of 10001) and show an actual input and what the output would be for it?
Rabe24
Rabe24 el 24 de Jun. de 2022
Thank you for your solution.
After researching array syntax that you told me about, I got the array which I wanted.
I changed p=zeros(H) to p=zeros(1,H), and the array changes to p(10001×100).
Thanks for your advice, I have learned a lot about matlab arrays.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by