For- loop to plot multiple images on a figure

1 visualización (últimos 30 días)
BN
BN el 14 de Abr. de 2020
Comentada: Geoff Hayes el 14 de Abr. de 2020
Hello,
I have 6 images that I want to insert on the one plot at the same time based on the latitude and longitude that specified in a table (namely coordinate). All 6 pictures name like this: filename1.png, filename2.png, filename3.png, ... filename6.png; Which should plot using the information in the coordinate table first, second, third ..., and sixth respectively.
I know how to plot one by one them using this code:
% This code for plot just first image
LowerLeftCornerLon = coordinates.LowerLeftCornerLon(1); % the first image uses the first row of the table, second must use second and so on
UperrRightCornerLon = coordinates.UperrRightCornerLon(1);
LowerLeftCornerLat = coordinates.LowerLeftCornerLat(1);
UperrRightCornerLat = coordinates.UperrRightCornerLat(1);
img1_lon = [LowerLeftCornerLon,UperrRightCornerLon];
img1_lat = [LowerLeftCornerLat,UperrRightCornerLat];
[c, ~, tr] = imread('img1.png');
im = image (img1_lon,img1_lat,flipud(c));
im.AlphaData = tr;
% then use hold on and do the same thing for the second picture but this time reading the second row of coordinate table
But I have some problems with writing a loop in order to plot all of them automatically.
Here is my try:
hold on % plot pictures on the previous plot
% first read all images from dir
if true
srcFiles = dir('F:\university\matlab\mypictures\*.png');
for i = 1 : length(srcFiles)
filename = strcat('F:\university\matlab\mypictures\',srcFiles(i).name);
IMAGES{i} = (filename);
end
end
for i=1:numel(IMAGES)
img_lowlat(i) = coordinates.LowerLeftCornerLat(i);
img_lowlon(i) = coordinates.LowerLeftCornerLon(i);
img_uplat(i) = coordinates.UperrRightCornerLat(i);
img_uplon(i) = coordinates.UperrRightCornerLon(i);
img_lon(i) = [img_lowlon(i),img_uplon(i)];
img_lat(i) = [img_lowlat(i),img_uplat(i)];
hold on
[c, ~, tr] = imread('IMAGES{i}');
im = image (img1_lon,img1_lat,flipud(c));
im.AlphaData = tr;
end
But this not accomplished well and after that, I get this error:
Unable to perform assignment because the indices on the left side are not
compatible with the size of the right side.
Did you know how can I do to fix my for loop and plot all images on the same plot successfully?
Really thank you
  7 comentarios
BN
BN el 14 de Abr. de 2020
Dear Geoff Hayes,
Thank you so much, it is fixed now and worked very well. I'll click on accept the answer if you post it as an answer.
It is really helpful. Thanks again
Best Regards
Geoff Hayes
Geoff Hayes el 14 de Abr. de 2020
Glad to have been able to help, Behzad!

Iniciar sesión para comentar.

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 14 de Abr. de 2020
The original error was concerned with
img_lon(i) = [img_lowlon(i),img_uplon(i)];
img_lat(i) = [img_lowlat(i),img_uplat(i)];
where a two-element array (right-hand side) was being assigned to a scalar on the left-hand side. This was replaced with
img_lon = [img_lowlon(i),img_uplon(i)];
img_lat = [img_lowlat(i),img_uplat(i)];
hold on
[c, ~, tr] = imread(IMAGES{i});
im = image (img_lon,img_lat,flipud(c));

Más respuestas (0)

Categorías

Más información sobre Lighting, Transparency, and Shading en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by