How to make M×N matrix in matlab function simulink
2 ビュー (過去 30 日間)
古いコメントを表示
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
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?
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!