number of columns on line 1 of ascii file must be the same as previous lines
2 views (last 30 days)
Show older comments
Carlos Ramada
on 6 Apr 2014
Commented: Image Analyst
on 6 Apr 2014
Hi guys,
I'm trying to load a variable of my main function in my subfunction and update it as here:
sub:
function [] = myfunction(q)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
fid = fopen('c:\\coeffs.txt','wt'); % Note the 'wt' for writing in text mode
fprintf(fid,'%f',q(i,:)); % The format string is applied to each element of a
fclose(fid);
i=i+1;
end
where 'i' is a variable of main. But I'm getting the error described above. Could you gyus helpe me out?
Thamk you
0 Comments
Accepted Answer
Image Analyst
on 6 Apr 2014
In the function definition, you need to pass in i:
function myfunction(q, i)
Then also pass in i when you call it.
myfunction(q, i);
4 Comments
Image Analyst
on 6 Apr 2014
Not sure if the backslash is messing it up. Try forward slash, which works just fine with Windows, or a single backslash:
fopen('c:/coeffs.txt','wt'); % or...
fopen('c:\coeffs.txt','wt');
More Answers (0)
See Also
Categories
Find more on File Operations 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!