필터 지우기
필터 지우기

How to make M×N matrix in matlab function simulink

조회 수: 2 (최근 30일)
Rabe24
Rabe24 2022년 6월 23일
댓글: Rabe24 2022년 6월 24일
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
dpb
dpb 2022년 6월 23일
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 2022년 6월 24일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by