3D graph from txt file

3 ビュー (過去 30 日間)
Helena
Helena 2013 年 4 月 17 日
回答済み: son nguyen xuan 2019 年 8 月 21 日
Hi All, I try to make 3D graph from text file 'output.txt'. This text file has 6 columns separated by commas and numerous rows. I need 3D graph from first 3 columns, say CX, CY, CZ, which have numerous rows. My code is below, but the graph displays only 1 point, which corresponds to the first row. Would anyone now, please, how to include data from all rows, so they are displayed in the graph? Thank you, Helena
fid = fopen('output.txt');
CX = [];
CY = [];
CZ = [];
temp = textscan(fid, '%f, %f, %f');
disp (temp);
CX(:,1) = cell2mat(temp(1));
CY(:,1) = cell2mat(temp(2));
CZ(:,1) = cell2mat(temp(3));
disp (CX);
disp (CY);
disp (CZ);
fclose(fid);
plot3(CY,CZ,CX,'*');
xlabel('Pressure deficit [100 m]');
ylabel('Water quality deficit [mg/L]');
zlabel('Pump energy costs [AUD]');
grid on;
axis square;

採用された回答

Yao Li
Yao Li 2013 年 4 月 17 日
I think the problem may result from the cell variable temp. You can try:
temp = cell2mat(textscan(fid, '%f, %f, %f'));
CX(:,1) = temp(:,1);
.
.
.
Since temp is in cell type, I don't think temp(1) is proper , but temp{1}
  7 件のコメント
Yao Li
Yao Li 2013 年 4 月 17 日
編集済み: Yao Li 2013 年 4 月 17 日
You may have to define the delimiter as follows:
temp = cell2mat(textscan(fid, '%f%f%f','delimiter', ','));
Helena
Helena 2013 年 4 月 17 日
Thank you, just a small modification:
temp = cell2mat(textscan(fid, '%f%f%f%f%f%f','delimiter', ','));
otherwise it loads columns 4-6 from the original txt file into the temp as extra rows, so I get 3 columns (which is OK), but 20 rows of data instead of 10 rows. So the final code is:
fid = fopen('output.txt');
CX = [];
CY = [];
CZ = [];
temp = cell2mat(textscan(fid, '%f%f%f%f%f%f','delimiter', ','));
disp (temp);
CX(:,1) = temp(:,1);
CY(:,1) = temp(:,2);
CZ(:,1) = temp(:,3);
disp (CX);
disp (CY);
disp (CZ);
fclose(fid);
plot3(CY,CZ,CX,'*');
xlabel('Pressure deficit [100 m]');
ylabel('Water quality deficit [mg/L]');
zlabel('Pump energy costs [AUD]');
grid on;
axis square;
Thanks a lot for you help!

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

その他の回答 (1 件)

son nguyen xuan
son nguyen xuan 2019 年 8 月 21 日
how can i get range of color for plot3?
thanks

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by