3D plot or surf plot problem

Hello all,
I have a problem, trying to solve it for the last two days, but could not succeed. ANY HELP WOULD BE GREATLY APPRECIATED.
I have a data in txt file called 'ecoli'. The first column and first row are wavelength parameters.
The rest of the matrix contains intensity values.
here is what i have done. I have deleted first element in first column and row because it was a X/Y text parameter.
Then i have reduced matrix by deleting first column and row, to get the rest of the intensity value matrix.
X=ecoli(:,1);
>> Y=ecoli(1,:);
>> ind=[1]
ind =
1
>> X(ind)=[]; >> Y(ind)=[]; >> ecoli(:,1)=[]; >> ecoli(1,:)=[]; >> Z=ecoli; >> plot3(X,Y,Z);
I get this error.
??? Error using ==> plot3 Vectors must be the same lengths.
Could somebody through some light on this problem. I know some where the lengths of vectors are not same thats y i could not plot.
Thanks

 Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 5 Mai 2011

0 Stimmen

Ecoli - fun stuff
size(X)
size(Y)
size(Z)
which one is different and why?

18 Kommentare

VISWANATH
VISWANATH am 5 Mai 2011
> size(X)
ans =
381 1
>> size(Y)
ans =
1 77
>> size(Z)
ans =
381 77
looks like i need to make X,Y into a matrix then plot. Is that correct?
Matt Fig
Matt Fig am 5 Mai 2011
surf(repmat(X,1,77),repamt(Y,381,1),Z)
Sean de Wolski
Sean de Wolski am 5 Mai 2011
What Matt said! (only the second repmat to be spelled correctly)
or:
[xx yy] = meshgrid(X,Y);
surf(xx,yy,Z);
Matt Fig
Matt Fig am 5 Mai 2011
Oops, thanks for the catch, Sean de. I didn't go with MESHGRID because the dimensions don't match up. Look at the dims for X,Y,Z.
% Z is 3-by-5.
X = round(rand(3,1)*4);
Y = round(rand(1,5)*200);
[xx,yy] = meshgrid(X,Y)% Not 3-by-5...
VISWANATH
VISWANATH am 5 Mai 2011
I tried it as well. Getting error
??? Error using ==> surf at 78
Data dimensions must agree.
Matt Fig
Matt Fig am 5 Mai 2011
What did you try, there have been two suggestions made in the comments?
Try the repmat solution shown above, making the spelling corrections of course:
surf(repmat(X,1,77),repmat(Y,381,1),Z)
VISWANATH
VISWANATH am 5 Mai 2011
Matt Fig, Both suggestions are leading to the same error!! i executed yours as well as Sean de's one. Still no solution....
Sean de Wolski
Sean de Wolski am 5 Mai 2011
perhaps:
surf(repmat(X(:),1,77),repmat((Y(:).'),381,1),Z)
Sean de Wolski
Sean de Wolski am 5 Mai 2011
Good catch with the meshgrid as well.
VISWANATH
VISWANATH am 5 Mai 2011
Still same error.... guys if any has idea do let me know plz..
Sean de Wolski
Sean de Wolski am 5 Mai 2011
The problem Viswanath is that you're not telling us everything. The above code works on my system:
X = (1:381).';
Y = (1:77);
Z = rand(381,77);
surf(repmat(X(:),1,77),repmat((Y(:).'),381,1),Z)
size(X)
size(Y)
size(Z)
ans =
381 1
ans =
1 77
ans =
381 77
So what is the FULL TEXT of the error message and what are the ACTUAL sizes.
Sean de Wolski
Sean de Wolski am 5 Mai 2011
(works for plot3 and mesh as well)
Matt Fig
Matt Fig am 5 Mai 2011
VISWANATH, you have not told us the correct dimensions if you are getting that error. Look at an example using the dimensions you give, just copy and paste:
Xe = round(rand(381,1)*4); % Your X dimensions.
Ye = round(rand(1,77)*300); % Your Y dimensions.
Ze = rand(381,77); % Your Z dimensions.
surf(repmat(Xe,1,77),repmat(Ye,381,1),Ze) % As above.
VISWANATH
VISWANATH am 6 Mai 2011
Hi Sean, the txt file that i gave in a hyperlink is obtained from a spectrometer.
I can not assume a matrix with random numbers for Z with 381 by 77. If you could able to read all the data given in the file and able to plot then let me know. Mean while i will give a few trails with suggestions provided by you guys.
You can email me in detail if you think it is appropriate, viswanath21@gmail.com
VISWANATH
VISWANATH am 6 Mai 2011
When i import ecoli.txt file, its size is 382 by 78. I have to read first row as Y vaue and first column as X value.
At this instant size(X)= 382 by 1, size(Y)= 1by 78.
Later i modify X and Y to 381 by and 1 by 77 respectively by removing first element in X as well as Y because first element is zero.
X and Y are wavelength values in the experiment.
Now i would like delete first column and first row in ecoli so that i get matrix of size 381 by 77, which contains only intensity values.
So i modified original ecoli 382 by 78 file to 381 by 77.
Now i assume Z=ecoli; matrix of size 381 by 77.
I want now to plot surf(X,Y,Z).
I have explained clearly now....if not let me know.
Teja Muppirala
Teja Muppirala am 6 Mai 2011
if isequal({size(X) size(Y) size(Z)},{[381 1] [1 77] [381 77]})
[Xgrid,Ygrid] = meshgrid(X,Y);
surf(X,Y,Z') %<-- Transpose because your data has X vertical, Y horizontal
else
disp('Your sizes are not correct.')
end
Teja Muppirala
Teja Muppirala am 6 Mai 2011
Oops, I guess I didn't really need to put that meshgrid line in there
VISWANATH
VISWANATH am 6 Mai 2011
Hey Teja, thanks for your help. I just used Z' instead of Z in surf(X,Y,Z'). I got the surface plot. Sorry for messing up myself....Thanks a mil...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Identification finden Sie in Hilfe-Center und File Exchange

Produkte

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by