exporting strings out of structure into a vector
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Gemma
el 30 de Abr. de 2015
Respondida: Gemma
el 2 de Mayo de 2015
Hello MatlabCentral-community,
I have a structure(1*k). For k images there is one time data. Now, I want to generate a vector (for each image one time data). But unfortunately, I'm struggling with this task.
I tried it by:
[filename, pathname] = uigetfile('C:\Users\Pictures\Cam\*.jpg', ...
'Select Pictures for processing',...
'Multiselect','on');
nop = length(filename); % number of pictures
for k = 1:nop
n = num2str(k);
info_all = imfinfo(fullfile(pathname, filename{k}));
end
Img_info(k) = info_all;
% until here it works (getting one single string)
timeinfo_single = Img_info.FileModDate
timevector(k) = Img_info(k).FileModDate
I would be very happy, if somebody could put me on the right track,
greetings,
Gemma
0 comentarios
Respuesta aceptada
Guillaume
el 30 de Abr. de 2015
As per Nobel's answer, you end you loop prematurely, the end should be in the last line.
it still won't work though as you can't put several strings (FileModDate) into a matrix, you have to use a cell array. Therefore, the end of your program should read:
timevector{k} = Img_Info(k).FileModDate;
end
Unless you meant to put a datenum in your timevector, in which case:
timevector(k) = datenum(Img_info(k).FileModDate);
end
By the way, I find your choice of variable name confusing. info_all is the information of a single image and Img_Info is the info of all images.
Finally, the way I would have written the same code would have been with just these three lines:
[filename, pathname] = uigetfile('C:\Users\Pictures\Cam\*.jpg', ...
'Select Pictures for processing',...
'Multiselect','on');
Img_Info = cellfun(@(fname) imfinfo(fullfile(pathname, fname)), filename);
timevector = datenum({Img_Info.FileModDate});
0 comentarios
Más respuestas (2)
Nobel Mondal
el 30 de Abr. de 2015
Your Img_info variable is storing only the information of the last (nop-th) image, since it is outside the for loop.
0 comentarios
Ver también
Categorías
Más información sobre Structures en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!