이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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
채택된 답변
Sean de Wolski
2011년 5월 5일
0 개 추천
Ecoli - fun stuff
size(X)
size(Y)
size(Z)
which one is different and why?
댓글 수: 18
VISWANATH
2011년 5월 5일
> 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
2011년 5월 5일
surf(repmat(X,1,77),repamt(Y,381,1),Z)
Sean de Wolski
2011년 5월 5일
What Matt said! (only the second repmat to be spelled correctly)
or:
[xx yy] = meshgrid(X,Y);
surf(xx,yy,Z);
Matt Fig
2011년 5월 5일
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
2011년 5월 5일
I tried it as well. Getting error
??? Error using ==> surf at 78
Data dimensions must agree.
Matt Fig
2011년 5월 5일
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
2011년 5월 5일
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
2011년 5월 5일
perhaps:
surf(repmat(X(:),1,77),repmat((Y(:).'),381,1),Z)
Sean de Wolski
2011년 5월 5일
Good catch with the meshgrid as well.
VISWANATH
2011년 5월 5일
Still same error.... guys if any has idea do let me know plz..
Sean de Wolski
2011년 5월 5일
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
2011년 5월 5일
(works for plot3 and mesh as well)
Matt Fig
2011년 5월 5일
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
2011년 5월 6일
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
2011년 5월 6일
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
2011년 5월 6일
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
2011년 5월 6일
Oops, I guess I didn't really need to put that meshgrid line in there
VISWANATH
2011년 5월 6일
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)
