save as txt file
44 views (last 30 days)
Show older comments
when i use save function, matlab save text file but with out data
matlab make many symboles insteade of data
where is the error please?
the code as below
clc, clear all, close all
syms x %define the vairable of(x)
f(x)=-1.8*x^4+6.03*x^3+57.03*x^2-171.41*x+30.30;
figure(1); hold on;
fplot(f);
xL = xlim;
yL = ylim;
line(xL, [0 0],'color','k','linewidth',2) %x-axis
title('plot of Polynomial function');
xlabel('X-axis');
ylabel('Y-axis');
%Find roots by using built in symbolic command
disp('Matlab built in Symbolic command (roots function)')
d=[-1.8,6.03,57.03,-171.41,30.30] %vector of coefficients
sol1=roots(d) %solve by roots function
plot(sol1,'ko') %draw solution
% geeneration 50 equally spaced points between smallest and largest root
figure(2);hold on
format shortG
LR=max(sol1)
SM=min(sol1)
gp=linspace(SM,LR,50);
pp=f(gp);
rootsdata=[gp' pp'];
plot(gp,pp,'rx')
title('plot genration spacing');
xlabel('X-axis');
ylabel('Y-axis');
save('rootsdata.txt','rootsdata');
0 Comments
Answers (1)
Image Analyst
on 12 Oct 2020
Try the -ascii option. From the help:
p = rand(1,10);
q = ones(10);
save('pqfile.txt','p','q','-ascii')
type('pqfile.txt')
or try using fprintf() instead of save().
3 Comments
Image Analyst
on 12 Oct 2020
Edited: Image Analyst
on 12 Oct 2020
Why do you want to use save? It's probably getting confused because it has no idea what format you want all these variables in. Therefore I recommend using fprintf() to write things out EXACTLY as you want them. Why does it have to be a text file anyway? What's wrong with just using the .mat format file?
See Also
Categories
Find more on Text Analytics Toolbox 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!