Appyling format to fprintf function via an array lookup
9 views (last 30 days)
Show older comments
I have a data file where I would like to automatically edit certain lines based on a user selection. Each line of the file I am editing has a different format. (ex. line 1 may be %4.1f whereas line 2 may be %6.2f)
Since the code is automated, and I don't know which lines the user would like to edit beforehand, I was planning on putting these formats into a string array. However, when I try to call from the array in the fprtinf function I get the following warning: "The function FPRINTF is apparently called with a cell array (argument 2)."
My code looks something like this (dumbed down version):
num_format = {'%4.1f' '%6.2f' '%5.3f'}; fprintf(fid,num_format(i),variable); (where i is [1,3])
Since MATLAB doesn't like my call to my lookup array in the fprintf function, is there another way to do this or correct my code?
0 Comments
Accepted Answer
Jan
on 9 Sep 2011
Use curly braces to access cell elements:
num_format = {'%4.1f' '%6.2f' '%5.3f'};
fprintf(fid, num_format{i}, variable);
0 Comments
More Answers (0)
See Also
Categories
Find more on Data Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!