Help loading data files using a dialogue box
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Voir également
Catégories
En savoir plus sur Large Files and Big Data dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!