Help loading data files using a dialogue box

조회 수: 8 (최근 30일)
David González Santana
David González Santana 2016년 10월 8일
편집: KSSV 2016년 10월 8일
Hi, I am writing a small program which will upload data files after the user inputs the data file range and the initial part of the file (which is normally some text, in my case ccc).In this case I have 4 data files called ccc131, ccc133, ccc135 and ccc137
I need help in two parts:
1) after the user inputs the initial text, I have to be able to use it in the loading data section, how do I do this, for example if it was a number I would use str2num
2)text+ is wrong, the objective is to have: matFileName = sprintf(ccc%d.dat', k); (but ccc should be obtained from the dialogue box, since it can change to another text in future data sets)
The code I already have is the following:
% Program to get all wanted .dat data
close all
clear all
clc
%%Questions
% A dialogue box appears with 4 questions, it wants to know the initial
% part of the data set, the starting value, the final value and the
% increase between the files
prompt = {'Continuos part of the data files','Initial value:','Final value:', 'Increase between files:'};
dlg_title = 'Information about data';
num_lines = 1;
defaultans = {'ccc', '131', '137', '2'};
answer = inputdlg(prompt,dlg_title,num_lines,defaultans);
% Transform answer into usable data
text=(answer{1,1}); % what the file starts with *(PART 1 OF NEEDED HELP)*
[a]= str2num(answer{2,1}); % initial value
[b]= str2num(answer{3,1}); % final value
[c]= str2num(answer{4,1}); % step between values
%%Loading data
for k = a:c:b;
% Create a mat filename, and load it into a structure called matData.
matFileName = sprintf(text+'%d.dat', k); % *HOW DO I LOAD THE TEXT (PART 2)*
if exist(matFileName, 'file');
matData = load(matFileName);
eval(['matData',num2str(k),' =load(matFileName)']);
else
fprintf('File %s does not exist.\n', matFileName);
end
end

답변 (1개)

KSSV
KSSV 2016년 10월 8일
편집: KSSV 2016년 10월 8일
Once user inputs the text..you can merge text and number using strat().
filename=strcat(cccc,num2str(131),'.dat')
You can put the above in loop too.
Or you can get all filenames starting with cccc using
d = dir('cccc*')

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by