Filter löschen
Filter löschen

Repeat coordinates (arranged on the same y and different x) over different values of y

1 Ansicht (letzte 30 Tage)
Hi! I need to achieve this by knowing the 'green' coordinates ("row_c") and the repeat intervals ("val"):
I tried this way but I can only generate the first (red) line:
load val.mat
load row_c.mat
r_add = {};
for k = 1:width(val)
y_new = row_c(1,2) - val(1,k);
r = height(row_c);
repetition = repmat(y_new,r,1);
r_new = row_c;
r_new(:,2) = repetition;
r_add = [r_add;{r_new}];
end
r_add_mat = cell2mat(r_add);
figure
plot(row_c(:,1),row_c(:,2),'g.','Markersize',15);
hold on
plot(r_new(:,1),r_new(:,2),'r.','Markersize',15);
% plot(r_add_mat(:,1),r_add_mat(:,2),'m.','Markersize',10);
hold off
axis equal
set(gca, 'YDir','reverse')
EDIT: add files

Akzeptierte Antwort

Voss
Voss am 28 Okt. 2023
Bearbeitet: Voss am 28 Okt. 2023
load row_c
load val
I think this is what you're going for:
r_add = [];
r = height(row_c);
r_new = row_c;
for k = 1:numel(val)
r_new(:,2) = repmat(r_new(1,2)-val(1,k), r, 1);
r_add = [r_add; r_new];
end
figure
plot(row_c(:,1),row_c(:,2),'g.','Markersize',15);
hold on
plot(r_add(:,1),r_add(:,2),'r.','Markersize',15);
hold off
axis equal
set(gca, 'YDir','reverse')
xlim([-90 -85])
ylim([104 108])
An alternative is:
[x,y] = meshgrid(row_c(:,1), row_c(1,2)-[0 cumsum(val)]);
figure
plot(x(1,:),y(1,:),'g.','Markersize',15);
hold on
plot(reshape(x(2:end,:),[],1),reshape(y(2:end,:),[],1),'r.','Markersize',15);
hold off
axis equal
set(gca, 'YDir','reverse')
xlim([-90 -85])
ylim([104 108])

Weitere Antworten (1)

Matt J
Matt J am 28 Okt. 2023
Bearbeitet: Matt J am 28 Okt. 2023
load row_c ; load val
x=row_c(:,1);
y0=row_c(1,2);
%%% Engine
[X,Y]=ndgrid(x, flip(y0-cumsum(val)));
scatter(X(:),Y(:),'r','filled'); hold on
scatter(X(:,end), Y(:,end),'g','filled'); hold off
set(gca, 'YDir','reverse'); axis padded
  4 Kommentare
Alberto Acri
Alberto Acri am 28 Okt. 2023
Sorry, I thought I had attached them! I have now added them!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by