Import Data Into Workspace Issue
1 回表示 (過去 30 日間)
古いコメントを表示
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 :)
0 件のコメント
採用された回答
Nagarjuna Manchineni
2017 年 6 月 21 日
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:
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Import, Export, and Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!