getting data type from a prompt in fread()

조회 수: 2 (최근 30일)
Hassan
Hassan 2011년 4월 23일
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);

채택된 답변

Oleg Komarov
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!
  댓글 수: 2
Matt Fig
Matt Fig 2011년 4월 23일
Now it is you who is fast!
Hassan
Hassan 2011년 4월 23일
thanks a lot Oleg.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by