How to fill a matrix column by column better than by a for loop?
古いコメントを表示
Want to parametrize areas for plotting/numerical integration/whatnot.
E.g. x-values: 0..1
y-values: x-1 ... x^3+1
This does the job, but it is awful:
xx=0:0.1:1;
nxx=length(xx);
nyy=10;
xm=repmat(xx',1,nyy);
ym=zeros(nxx,nyy);
for ii=1:nxx
xii=xx(ii);
ym(ii,:)=linspace(xii-1,xii^3+1,nyy);
end
Thanks in advance!
採用された回答
その他の回答 (1 件)
Ulrich Becker
2020 年 6 月 26 日
編集済み: Ulrich Becker
2020 年 6 月 26 日
1 件のコメント
Tommy
2020 年 6 月 27 日
Nice and neat, thanks for this! In case anyone reading isn't already aware:
a=[1;2;3] % is a column vector
a(:) % is still a column vector
カテゴリ
ヘルプ センター および File Exchange で Resizing and Reshaping Matrices についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!