フィルターのクリア

Creating a matrix using arrays

4 ビュー (過去 30 日間)
Anna M
Anna M 2020 年 3 月 9 日
コメント済み: Anna M 2020 年 3 月 9 日
I am trying to create a matrix where each row is xstart:inc:xend, where the value begins at xstart and is increased by xinc to xend. so, a 30 x 37 matrix.
I am using the following:
XL = 96.5;
dx = 0.423;
n = 1:30;
xstart = 0+n*dx;
xend = XL-n*dx;
xinc = xend/37;
what I have so far,
xr = zeros(30,37);
for i = 1:length(n)
xr(i,:) = xstart(1,i):xinc(1,i):xend(1,i);
end
I have tried different variations of the left side, xr(i), but I am still getting an error that states, "Unable to perform assignment because the indices on the left side are not compatible with the size of the right side."
I computed the following, but I was wondering if I have to do this 30 times.
xr1 = xstart(1,1):xinc(1,1):xend(1,1);
xr2 = xstart(1,2):xinc(1,2):xend(1,2);
xr3 = xstart(1,3):xinc(1,3):xend(1,3);

採用された回答

Akira Agata
Akira Agata 2020 年 3 月 9 日
編集済み: Akira Agata 2020 年 3 月 9 日
How about the following?
XL = 96.5;
dx = 0.423;
n = 1:30;
xstart = 0+n*dx;
xend = XL-n*dx;
xr = zeros(30,37);
for kk = 1:length(n)
xr(kk,:) = linspace(xstart(kk),xend(kk),37);
end
or
xr = arrayfun(@(x,y) linspace(x,y,37),xstart',xend','UniformOutput',false);
xr = cell2mat(xr);
  1 件のコメント
Anna M
Anna M 2020 年 3 月 9 日
Both work for what I need! Thank you very much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by