Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong output when reading a file with fscanf #976

Closed
Lokinyx opened this issue Oct 18, 2023 · 0 comments · Fixed by #978
Closed

wrong output when reading a file with fscanf #976

Lokinyx opened this issue Oct 18, 2023 · 0 comments · Fixed by #978

Comments

@Lokinyx
Copy link
Contributor

Lokinyx commented Oct 18, 2023

% create an file
fID1 = fopen('myoutput1.txt','w');
for n = 1:4
b1 = n; b2 = n^2; b3 = n^3;
fprintf(fID1,'%7u %7u %7u \r',b1,b2,b3);
end
fclose(fID1);

% then reopen it
fID1 = fopen('myoutput1.txt','r');
for n = 1:4
b = fscanf(fID1,'%7u %7u %7u \r',3)
end
fclose(fID1);

I expect the output:
b =

 1
 1
 1

b =

 2
 4
 8

b =

 3
 9
27

b =

 4
16
64

but from Nelson I get
b =

 []

b =

 []

b =

 1

b =

 []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant