Creating a matrix using arrays
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Anna M
am 9 Mär. 2020
Kommentiert: Anna M
am 9 Mär. 2020
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);
0 Kommentare
Akzeptierte Antwort
Akira Agata
am 9 Mär. 2020
Bearbeitet: Akira Agata
am 9 Mär. 2020
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);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!