필터 지우기
필터 지우기

Not able to get fprintf to print all columns

조회 수: 2 (최근 30일)
Oscar Hernandez
Oscar Hernandez 2016년 5월 2일
댓글: Oscar Hernandez 2016년 5월 2일
Hello, I am having trouble writing my data to a .dat file. I have data with a set number of columns (512) plus the header for a total of 513. The number of data rows depends on how much data I take. So, my data will look like this:
date 17.53 18.93 100.0 ....
date 36.2 255.2 255.1 ....
etc
My goal is to write each row to the file, one set at a time using the for loop. The code for that is below:
%writes output radiance file (dat file)
[file, dir] = uiputfile('*.dat', 'Save Radiance File:');
fid05 = fopen([dir file], 'wt+');
header = ['lambda', strcat(dates, {' '}, times)].';
results = num2cell([lambda.'; cell2mat(radiance).']);
fullData = [header, results];
[nrows,ncols] = size(fullData);
for row = 1:nrows
fprintf(fid05,formatSpec, fullData{row,:});
end
My issue is that I only get the first column written to the file, nothing else. So my file ends up like this:
date
date
date
date
...
no data next to the date. Would you happen to know why this is and what direction I should look to fix the issue. Thank you for all your help!
  댓글 수: 2
Walter Roberson
Walter Roberson 2016년 5월 2일
What is your formatSpec?
Oscar Hernandez
Oscar Hernandez 2016년 5월 2일
I see where that would be the issue. Originally, I did not have the format spec variable, and that was where I was getting the single column write only. Now, my format spec should be %s %f %f.... the issue is that I have 512 floating point values. Am I required to write all these out, or is there another way to format? Thank you for your answers

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

채택된 답변

Walter Roberson
Walter Roberson 2016년 5월 2일
fmtSpec = ['%s ', repmat('%f ', 1, 511), '%f\n'];

추가 답변 (1개)

Kevin
Kevin 2016년 5월 2일
Seems like you have not defined the variable formatSpec.

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by