Borrar filtros
Borrar filtros

Import Data Into Workspace Issue

4 visualizaciones (últimos 30 días)
itend
itend el 13 de Jun. de 2017
Respondida: Nagarjuna Manchineni el 21 de Jun. de 2017
Hello,
I need some help with the following situation:
1) I have a folder (bkg_folder) containing numerous .spe files.
2) I have a function (readSPE) which can read a .spe file and output a 3D matrix of values
3) I am trying to create a script which imports all the .spe files in bkg_folder into matlab and stores them as individual matrices. I'd like the names of these matrices to match the names of the corresponding files.
Here is what I have so far:
%Specify folder
bkg_folder = 'C:\Users\Irwin\Desktop\Matlab\photon_count_project\Background';
%Ensure folder exists
if ~isdir(bkg_folder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', bkg_folder);
uiwait(warndlg(errorMessage));
return;
end
%Generate List of All Files in Folder
bkgPattern = fullfile(bkg_folder,'*.spe');
bkg_files = dir(bkgPattern);
for i = 1:length(bkg_files)
basebkgName = bkg_files(i).name;
fullbkgName = fullfile(bkg_folder, basebkgName);
fprintf(1, 'Now reading %s\n', fullbkgName);
image = readSPE(fullbkgName);
end
The issue I am encountering is having the readSPE function save each .spe file to a separate 3D matrix (which would be named the same as its corresponding file).
Please help, let me know if anymore information is necessary!
Thanks :)

Respuesta aceptada

Nagarjuna Manchineni
Nagarjuna Manchineni el 21 de Jun. de 2017
You can use 'fileparts' command to get the name of the file:
[pathstr,name,ext] = fileparts(filename); % Read the file name
Process/read the data from the file
eval([matlab.lang.makeValidName(name) '=' data ';']); % Assign the value to a variable named 'filename'
See the following documentation link for more information:

Más respuestas (0)

Categorías

Más información sobre Data Import and Export 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!

Translated by