How to extract the first column of a structure array and save it as a different array
195 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
A LL
el 13 de Jul. de 2022
Comentada: A LL
el 15 de Jul. de 2022
I have a structure array containing the names of my files in the first column.
I want to extract only the names of my files and store it in a different array.
I tried the following but it does not work:
% My struct array with 15560 elements where the name in the first column
files = dir('seaice_conc_daily_nh_*_v04r00*.nc');
%I tried this would work but it only returns the name of the first
%element...
filenames = files.name
%I know I can call individual elements i with:
filenames_i = files(i).name
%But I want a new array with all the name of my files
Thank you
2 comentarios
Stephen23
el 15 de Jul. de 2022
"I have a structure array containing the names of my files in the first column."
Actually the names are stored in the field 'name'. The size of a structure is independent of how many fields it has:
Más respuestas (2)
Ruchika P Barman
el 13 de Jul. de 2022
It is my understanding that you have a structure array containing the names of your files in the first column of the structure array and are trying to extract only the names of the files and store it in a different array. The following code should help you achieve the same.
filenames = vertcat(files.name)
Tasneem
el 13 de Jul. de 2022
It is my understading that you are trying to extract first column from an array. so you could use files(:,1) to extract the first column and store the output in a different array.
The below is the code.
files = dir('seaice_conc_daily_nh_*_v04r00*.nc');
filenames = files(:,1);
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!