getting data type from a prompt in fread()
1 次查看(过去 30 天)
显示 更早的评论
I want to import an array using the fread(), I wonder if I can use a prompt to get the type of file. I tried the following code, it works if I type the data type inside the fread() but its not working when I enter them from the prompt. I appereciate your help.
FID = fopen(filename, 'r');
if FID < 0; error('Cannot open file');
end
% Skip the header here...
prompt = {'Enter the type of input data (float,uint32,int16,double):','Enter the type of output data (float,uint32,int16,double):'};
dlg_title = 'the type of input/output';
num_lines = 1;
def = {'double','double'};
answer = inputdlg(prompt,dlg_title,num_lines,def);
data_type=strcat(answer(1),'=>',answer(2));
Data = fread(FID, Inf, data_type); % Choose the correct format!
fclose(FID);
0 个评论
采纳的回答
Oleg Komarov
2011-4-23
data_type=strcat(answer(1),'=>',answer(2));
Should be
data_type = [answer{1},'=>',answer{2}]; % Curly brackets to access cell content!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!