save as txt file

조회 수: 43 (최근 30일)
Husam Aneed
Husam Aneed 2020년 10월 12일
댓글: Husam Aneed 2020년 10월 12일
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');

답변 (1개)

Image Analyst
Image Analyst 2020년 10월 12일
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
Image Analyst
Image Analyst 2020년 10월 12일
편집: Image Analyst 2020년 10월 12일
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 2020년 10월 12일
because I have homework from my professor and he ask in it save the data to txt

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Text Analytics Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by