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');

Antworten (1)

Image Analyst
Image Analyst am 12 Okt. 2020

0 Stimmen

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 Kommentare

Husam Aneed
Husam Aneed am 12 Okt. 2020
thank you its work but , matlab cant save second line
it give
Warning: Attempt to write an unsupported data type to an ASCII file.
Variable 'd2' not written to file.
gp=linspace(SM,LR,50);
pp=f(gp);
d1=gp';
d2=pp';
plot(gp,pp,'rx')
title('plot genration spacing');
xlabel('X-axis');
ylabel('Y-axis');
save('pqfile.txt','d1','d2','-ascii')
Image Analyst
Image Analyst am 12 Okt. 2020
Bearbeitet: Image Analyst am 12 Okt. 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?
Husam Aneed
Husam Aneed am 12 Okt. 2020
because I have homework from my professor and he ask in it save the data to txt

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Text Analytics Toolbox finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 12 Okt. 2020

Kommentiert:

am 12 Okt. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by