How do I plot 2 arrays against each other so that each row of the arrays corresponds to each data point

2 visualizaciones (últimos 30 días)
I have two arrays named XCoords and YCoords, each 6x4 and I would like them to be plotted so that each of the first rows are plotted against each other, then each of the second rows, etc.
clc
clear
x = 3;
y = 3;
Setupx = [0:x].';
Setupy = [0:y].';
X = [0 0 1 1 0 1];
Y = [0 1 1 0 0 1];
XCoords = X + Setupx
YCoords = Y + Setupy
plot(XCoords,YCoords)
xlim([-1 5])
ylim([-1 5])
When x is changed to 0, the correct output is given but is only for one row.

Respuestas (1)

DGM
DGM el 15 de Nov. de 2022
Editada: DGM el 15 de Nov. de 2022
I'm not really sure what the correct output is supposed to be. If it's supposed to be crossed boxes in a diagonal,
x = 3;
y = 3;
xoffset = 1;
Setupx = [0:x].' * xoffset;
Setupy = [0:y].';
X = [0 0 1 1 0 1];
Y = [0 1 1 0 0 1];
XCoords = X + Setupx;
YCoords = Y + Setupy;
plot(XCoords.',YCoords.')
xlim([-1 5])
ylim([-1 5])
If the boxes are supposed to be stacked vertically, you can set the xoffset to 0 (or otherwise simplify the code).
  2 comentarios
Oliver Rosenfield
Oliver Rosenfield el 15 de Nov. de 2022
Sorry no I meant like this:
I did this manually but I need it so that the code does however many rows and columns of boxes as x and y.
DGM
DGM el 15 de Nov. de 2022
I'm assuming you want them plotted as one curve per block, so:
% specify the number of blocks
nblocksx = 4;
nblocksy = 4;
% block offsets
osx = 0:nblocksx-1;
osy = 0:nblocksy-1;
[osx osy] = meshgrid(osx,osy);
% curve for one block
X = [0 0 1 1 0 1];
Y = [0 1 1 0 0 1];
% combine coordinates to form multiple curves
XCoords = X + osx(:);
YCoords = Y + osy(:);
plot(XCoords.',YCoords.')
xlim([-1 5])
ylim([-1 5])

Iniciar sesión para comentar.

Categorías

Más información sobre Array Geometries and Analysis en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by