显示 更早的评论
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
采纳的回答
Ecoli - fun stuff
size(X)
size(Y)
size(Z)
which one is different and why?
18 个评论
> 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?
surf(repmat(X,1,77),repamt(Y,381,1),Z)
What Matt said! (only the second repmat to be spelled correctly)
or:
[xx yy] = meshgrid(X,Y);
surf(xx,yy,Z);
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...
I tried it as well. Getting error
??? Error using ==> surf at 78
Data dimensions must agree.
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)
Matt Fig, Both suggestions are leading to the same error!! i executed yours as well as Sean de's one. Still no solution....
perhaps:
surf(repmat(X(:),1,77),repmat((Y(:).'),381,1),Z)
Good catch with the meshgrid as well.
Still same error.... guys if any has idea do let me know plz..
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.
(works for plot3 and mesh as well)
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.
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
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.
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
Oops, I guess I didn't really need to put that meshgrid line in there
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...
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Data Type Identification 的更多信息
产品
标签
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
