problems plotting multiple 2D curves in 3D

I have 70 (x,y) data curves which i would like to plot in 3D. the x axis is the same for all 70 data sets, it is only y that changes from data set to data set.
so what i would like to do is assign z = 1 for the first curve, z = 2 for the second curve ects.
the code is shown below. i will gladly post the "readSWING" code if it relevant
% Load the data into matlab using "readSWING"
for n = 0:69
eval(['s' num2str(n) ' = readSWING(''C:\path\sample_rad' num2str(n) '.dat'');']) % frame "n" is read into "sn"
% plot the data in 3D
figure(1)
set(gca,'xscale','lin')
set(gca,'yscale','log')
set(gca,'zscale','lin')
hold on
set(gca,'fontsize',16)
set(gca,'linewidth',1.3)
xlabel('Q (Å^{-1})','fontsize',16)
ylabel('Detector counts in 1 sec.','fontsize',16)
eval(['plot3(s' num2str(n) '(:,1),s' num2str(n) '(:,2),repmat(n,1111),''Color'',[1 0 ' num2str(n) '/70*1],''linewidth'',1.5)'])
hold on
end
EDIT: the code runs very slow. i typically abort it by ctrl+c after a few curves
When i run the script i just get a normal 2D whit all the curves superimposed. My attempt is based on the solution to a similar problem given here: http://www.mathworks.com/matlabcentral/newsreader/view_thread/299404 where following code works
plot3(x1, y1, repmat(z1,size(x1)))
hold on
plot3(x2, y2, repmat(z2,size(x2)))
plot3(x3, y3, repmat(z3,size(x3)))
and so on.
size(x) is always 1111 as the x-axis is the same for all 70 curves. i use repmat((n+1),1111) because n goes from 0 to 69. this is because the files are named "data_0" to "data_69". it is not as important as being able to plot in 3D so i can remove that if it cause problems. this is of course also the case for the coloring.
i currently use matlab R2011b but i believe my university has license for the newest version as well. so i can upgrade if relevant

回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 1 月 9 日

0 投票

2 件のコメント

Martin Nors Pedersen
Martin Nors Pedersen 2013 年 1 月 10 日
Hi Walter
thank you for your comment. as you can probably see, i'm not an experience matlab user :)
i have begun tidying up the script(s), removing all the "eval" calls. i used the import wizard to generate a new function to import one data file. the code is shown below
function importfile(fileToRead1)
%IMPORTFILE(FILETOREAD1)
% Imports data from the specified file
% FILETOREAD1: file to read
% Auto-generated by MATLAB on 10-Jan-2013 14:32:55
DELIMITER = ' ';
HEADERLINES = 28;
% Import the file
newData1 = importdata(fileToRead1, DELIMITER, HEADERLINES);
% Create new variables in the base workspace from those fields.
vars = fieldnames(newData1);
for i = 1:length(vars)
assignin('base', vars{i}, newData1.(vars{i}));
end
the function works fine for importing one data file. but things go wrong when i try to write a loop for importing all 70 data files. i tried to use the procedure suggested in your link, shown below
for i=1:10
A(i) = % some equation
end
which i turn into
for n = 0:69
s(n) = importfile('C:\path\filename' num2str(n) '.dat') % frame "n" is read into "s(n)"
end
but i get the error message
Error: File: New_attempt.m Line: 2 Column: 88
Unexpected MATLAB expression.
Including the "A = zeros(1,10);" step does not change anything, but the guide also states the step is not necessary.
can anyone help me with getting the data properly imported into matlab so i proceed with working on a 3D plot? :)
Martin Nors Pedersen
Martin Nors Pedersen 2013 年 1 月 10 日
after re-reading the link i can see that i should use the second suggestion
for i=1:10
A{i} = 1:i;
end
which i turned into
for n = 0:69
s{n} = importfile('C:\path\file' num2str(n) '.dat') % frame "n" is read into "s{n}"
end
but it still get the error message
"Error: File: New_attempt.m Line: 2 Column: 88
Unexpected MATLAB expression."

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

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

質問済み:

2013 年 1 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by