Filter löschen
Filter löschen

how to access values inside a matrix or array in a 'for' loop??

1 Ansicht (letzte 30 Tage)
Manoj Murali
Manoj Murali am 4 Feb. 2012
Bearbeitet: Jan am 30 Sep. 2013
suppose i hav two matrices or arrays named m and n.They have 4 values each like this.
m=56 67 89 103
n=45 78 92 71
now i need to plot 4 dots on an image using the above corresponding m and n values as (x,y) coordinates.So how to do it.i have written a code for this.But it is showing error.Any one plz hlp me fix this.
for i = 0:3
x=m.i;
y=n.i;
h=imread('C:\Users\Manoj\Desktop\sorry.jpg');
imshow(h)
hold on;
plot(x,y,'r.','MarkerSize',15)
end
I dont know how to access the values inside the m and n.So i doubt the error is in the steps m.i and n.i.
The output of the program must be an figure window with four dots plotted at the four (x,y) points.Where x,y must take values from m and n respectively.Help me plz..

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 4 Feb. 2012
h=imread('C:\Users\Manoj\Desktop\sorry.jpg');
imshow(h)
hold on;
plot(m,n,'r.','MarkerSize',15)

Weitere Antworten (1)

the cyclist
the cyclist am 4 Feb. 2012
This
m.i
is not how to access the i th element of m. Use
x=m(i)
y=n(i)
instead. Also, though, you shouldn't have to use a for loop at all. You can do this with a vector, and just do
plot(m,n,'r.','MarkerSize',15)
  3 Kommentare
Manoj Murali
Manoj Murali am 4 Feb. 2012
sir,as u told i used this after modifying m.i to m(i)...but my output showed only one dot on the image at the last values of m and n.I need all the 4 points to b plotted sir..cud u help me..??
for i = 1:4
x=m(i);
y=n(i);
h=imread('C:\Users\Manoj\Desktop\sorry.jpg');
imshow(h)
hold on;
plot(x,y,'r.','MarkerSize',15)
end
Manoj Murali
Manoj Murali am 4 Feb. 2012
While the other method worked,that doing it with out the for loop.But
to gain some insight on how to implement this using the for loop am asking u..plz dont mind sir..help me to plot all the 4 points on the image instead of only the last 4th point being plottted as i told u in previous comment....

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Characters and Strings 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!

Translated by