matlab matrix to ascii with blank rows

2 ビュー (過去 30 日間)
maurizio
maurizio 2011 年 2 月 14 日
Hello,
I'm trying to export a matrix to ascii file, to then plot it using GNUPLOT. To plot a surface, I would need a matrix with blank rows in it, something like:
A(1) B(1) C(1, 1)
A(1) B(2) C(1, 2)
A(1) B(3) C(1, 3)
A(2) B(1) C(2, 1)
A(2) B(2) C(2, 2)
A(2) B(3) C(2, 3)
but I can't find any documentation about it.
Any idea?
Thanks in advance
  3 件のコメント
Matt Tearle
Matt Tearle 2011 年 2 月 15 日
My question would be: why not just plot in MATLAB?
maurizio
maurizio 2011 年 2 月 16 日
Because when I'm going to start writing the PhD thesis, I will include a lot of plots (Letx -> eps) and everytime I used Matlab there was always something I had to fix with CorelDraw. I love Matlab but I've never been 100% satisfied with its plotting capability. Do not get me wrong, it's more than enough to visualize data, but as I sayd I've alaways had to modified the exported eps with another software to reach a publishable quality.
Third, I'm very curious by nature and due to the fact that I will produce a lot of plots in the next months, I think it's a good chance to learn something more about GNUPLOT.
Thanks for your question, bye
Maurizio

サインインしてコメントする。

採用された回答

Oleg Komarov
Oleg Komarov 2011 年 2 月 14 日
Look at fprintf
Oleg

その他の回答 (2 件)

Igor
Igor 2011 年 2 月 14 日
better than fprintf :)
dlmwrite
  2 件のコメント
Oleg Komarov
Oleg Komarov 2011 年 2 月 14 日
You can't use dlmwrite if the OP is actually trying to write A(1,1) and not the element itself ata that position.
And easier to use maybe, don't know about better.
Walter Roberson
Walter Roberson 2011 年 2 月 14 日
And you aren't going to get the blank lines in dlmwrite() unless you loop using the row offset and the -append option. fprintf() would be easier.

サインインしてコメントする。


maurizio
maurizio 2011 年 2 月 15 日
Thnks, fprint works perfectly:
A = [1 2 3 4 5;
5 4 3 2 1;
1 2 3 4 5];
B = [10 20 30 40 50];
t = [10 20 30];
for l = 1:length(t)
for m = 1:length(B)
C(m,1) = t(l);
C(m,2) = B(m);
C(m,3) = A(l,m);
fid = fopen('PlotVariable.dat', 'a');
fprintf(fid, '%5.3f %5.3f %5.3f \n', C(m,1:3));
fclose(fid)
end
fid = fopen('VarToPlot.dat', 'a');
fprintf(fid, '\n');
fclose(fid)
end
thanks again
Maurizio

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by