Filter löschen
Filter löschen

How do I add multiple values stored in a matrix?

3 Ansichten (letzte 30 Tage)
matlabkid602
matlabkid602 am 23 Jun. 2017
Kommentiert: matlabkid602 am 10 Jul. 2017
Hello all.
I have a grid of data points that range from 1:30 on the x axis in steps of 1, and .25:30 on the y axis in steps of .25, 3600 entries in total.
I need to find a way to store vectors from 5 selected points on the grid to the origin, and then from the origin to all 3600 points on the grid and store them.
How would I do this with a for loop?
Some guidance please?
  1 Kommentar
dpb
dpb am 23 Jun. 2017
What do mean, precisely, by "store a vector" ?
The coordinates of a vector to any point from the origin are just the values at that point and [0 0]

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Vinoth Venkatesan
Vinoth Venkatesan am 6 Jul. 2017
I'm assuming the idea is to store the distance between the points (specific selected points/all of them) and the origin. This can be done as follows using 'for' loops in MATLAB: for loops in MATLAB
distances = zeros(120,30);
for i = 1:30
x = i;
for j = 1:120
y = 0.25*j;
distances(j,i) = norm([x,y]);
end
end
Please refer to the norm function at the MathWorks documentation page.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by