필터 지우기
필터 지우기

faster way of using fprintf

조회 수: 3 (최근 30일)
Richard
Richard 2012년 3월 12일
If I have a large cell array say 10x26 where the first two columns are strings and the remaining columns are all numbers. Instead of having to write fprintf(1,'%s\t%s\t%f\t... and so on) is there a faster method which involves not having specify all of the fixed point notations.

채택된 답변

Jacob Halbrooks
Jacob Halbrooks 2012년 3월 12일
You might try using REPMAT to specify one format for the numeric data that you repeat for the number of numbers you have. For example:
myData = {'a','b',1,2,3,4};
fSpec = repmat('%f\t',1,size(myData,2)-2);
fprintf(1,['%s\t%s\t' fSpec], myData{:})
  댓글 수: 1
Oleg Komarov
Oleg Komarov 2012년 3월 12일
You have to add an additional step if you have more than one line of data:
myData = myData.';

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by