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

2 visualizzazioni (ultimi 30 giorni)
Alberto Acri il 28 Ott 2023
Modificato: Matt J il 28 Ott 2023
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:
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;
end
figure
plot(row_c(:,1),row_c(:,2),'g.','Markersize',15);
hold on
plot(r_new(:,1),r_new(:,2),'r.','Markersize',15);
hold off
axis equal
set(gca, 'YDir','reverse')
0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Risposta accettata

Voss il 28 Ott 2023
Modificato: Voss il 28 Ott 2023
I think this is what you're going for:
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);
end
figure
plot(row_c(:,1),row_c(:,2),'g.','Markersize',15);
hold on
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])
0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Più risposte (1)

Matt J il 28 Ott 2023
Modificato: Matt J il 28 Ott 2023
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
4 CommentiMostra 2 commenti meno recentiNascondi 2 commenti meno recenti
Alberto Acri il 28 Ott 2023
Sorry, I thought I had attached them! I have now added them!
Matt J il 28 Ott 2023
Very well. I've incorporated them into my answer.

Accedi per commentare.

Categorie

Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by