How to I turn a fprintf column of values into a matrix
3 ビュー (過去 30 日間)
古いコメントを表示
I have a list of values in a column from my 'fprintf' code:
fprintf ('x \t\t y (Euler)\t y (analytical) \n')
fprintf ('%f \t %f\t %f\n',x0,y,f(x0))
for x = x0 : h : xn-h
y = y + dy(x,y)*h
x = x + h
fprintf ('%f \t %f\t %f\n',x,y,f(x))
end
This gives me a considerable number of values in a fprintf code. I however want to plot my two 'Y' values against eachother of a graph against the x value
0 件のコメント
回答 (1 件)
James Tursa
2020 年 12 月 1 日
編集済み: James Tursa
2020 年 12 月 1 日
You can save all the values for plotting. E.g.,
xp = x0;
yp = y;
fp = f(x0);
k = 1;
for x = x0 : h : xn-h
y = y + dy(x,y)*h
x = x + h
fprintf ('%f \t %f\t %f\n',x,y,f(x))
k = k + 1;
xp(k) = x;
yp(k) = y;
fp(k) = f(x);
end
Then you can plot xp, yp, fp.
If you have a large number of values to plot, you should probably preallocate the plotting variables. E.g.,
n = numel(x0 : h : xn-h);
xp = zeros(n,1);
yp = zeros(n,1);
fp = zeros(n,1);
xp(1) = x0;
yp(1) = y;
fp(1) = f(x0);
etc.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!