PLOT ARRAY OF SURF PLOTS IN ONE PLOT
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I have mutltiple text files with x, y, and z data attached. This files are named in matrix form according to their location.
I would like to create one surf plot that combine the surf plot of the individual text files. The x, and y data can be continuous row and column numbering but the z data remain the same.
Will appreciate a help. Pls let me know if you need more info.
Thanks in advance.
채택된 답변
Walter Roberson
2022년 6월 16일
load() each file. Extract column 3. reshape it as 614 x 588 and then transpose it to 588 x 614. Store in a cell array according to the information from the file name.
When they are all loaded, cell2mat to get the overall Z matrix.
댓글 수: 7
Thanks. But I am sorry. Can i get a sample code that does all the above mentioned? not really clear to me
D11 = load('1-1.txt');
D12 = load('1-2.txt');
D21 = load('2-1.txt');
D22 = load('2-2.txt');
C{1,1} = reshape(D11(:,3), 614, []).';
C{1,2} = reshape(D12(:,3), 614, []).';
C{2,1} = reshape(D21(:,3), 614, []).';
C{2,2} = reshape(D22(:,3), 614, []).';
S = cell2mat(C);
surf(S, 'edgecolor', 'none')
In the case where the files might not be exactly the size of the given ones:
D11 = load('1-1.txt'); c11 = max(D11(:,2));
D12 = load('1-2.txt'); c12 = max(D12(:,2));
D21 = load('2-1.txt'); c21 = max(D21(:,2));
D22 = load('2-2.txt'); c22 = max(D22(:,2));
C{1,1} = reshape(D11(:,3), c11, []).';
C{1,2} = reshape(D12(:,3), c12, []).';
C{2,1} = reshape(D21(:,3), c21, []).';
C{2,2} = reshape(D22(:,3), c22, []).';
S = cell2mat(C);
surf(S, 'edgecolor', 'none');
The cell2mat() step will fail if the arrays are not compatible sizes.
If the arrays are not compatible sizes, then you have to define how you want to stitch them together.
OLUWAFEMI AKINMOLAYAN
2022년 6월 19일
편집: OLUWAFEMI AKINMOLAYAN
2022년 6월 19일
Thanks @Walter Roberson
Compatible sizes means not divible be each other right?
The second code failed for different sizes. Error below.
"Error using cat
Dimensions of arrays being concatenated are not consistent.
Error in cell2mat (line 83)
m{n} = cat(1,c{:,n});
Error in Cellarray3 (line 11)
S = cell2mat(C); "
How do i stitch incompatible array sizes together?
Compatible sizes: the number of columns of {1,1} and {2,1} must be the same as each other. The number of columns of {1,2} and {2,2} must be the same as each other. The sum of the number of rows of {1,1} and {2,1} must be the same as the sum of the number of rows of {1,2} and {2,2} .
That is, each column of the cell array is put together into a single larger column, and then once all of the columns are put together, the results are put side by side, so the total number of rows has to be the same in each case.
If that is not the case, then you need to decide how you want the portions to go together.
For example, should the maximum height of patches in a row be found, and all patches in that row should be placed at the top of an area that tall with the shorter ones being padded with zeros (which might look fine at the bottom but is probably going to look odd in-between.)
Or should the maximum height of patches in a row to be found, and all patches in that row should be centered in an array the height of the tallest one?
You should give a couple of diagrams of what you would like if the sizes are different.
I really didnt grabs fully your last 3 paragraphs. However, the fourth paragraph might be the right portioning.
I attached 4 files with incompatible sizes. Would appreciate a fix for the code. Thanks.
filename11 = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1037665/1,1.txt';
filename12 = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1037670/1,2.txt';
filename21 = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1037675/2,1.txt';
filename22 = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1037680/2,2.txt';
D11 = readmatrix(filename11); c11 = max(D11(:,2));
D12 = readmatrix(filename12); c12 = max(D12(:,2));
D21 = readmatrix(filename21); c21 = max(D21(:,2));
D22 = readmatrix(filename22); c22 = max(D22(:,2));
C{1,1} = uint8(reshape(D11(:,3), c11, [])).';
C{1,2} = uint8(reshape(D12(:,3), c12, [])).';
C{2,1} = uint8(reshape(D21(:,3), c21, [])).';
C{2,2} = uint8(reshape(D22(:,3), c22, [])).';
C
C = 2×2 cell array
{580×596 uint8} {580×608 uint8}
{588×614 uint8} {580×596 uint8}
rows = cellfun(@(M) size(M,1), C);
cols = cellfun(@(M) size(M,2), C);
targcols = max(cols, [], 1);
targrows = max(rows, [], 2);
colpadleft = cellfun(@(M) [M, zeros(size(M,1),targcols(1)-size(M,2))], C(:,1), 'uniform', 0);
colpadright = cellfun(@(M) [M, zeros(size(M,1),targcols(2)-size(M,2))], C(:,2), 'uniform', 0);
colpad = [colpadleft, colpadright];
colpad
colpad = 2×2 cell array
{580×614 uint8} {580×608 uint8}
{588×614 uint8} {580×608 uint8}
rowpadup = cellfun(@(M) [M; zeros(targrows(1)-size(M,1),size(M,2))], colpad(1,:), 'uniform', 0);
rowpaddown = cellfun(@(M) [M; zeros(targrows(2)-size(M,1),size(M,2))], colpad(2,:), 'uniform', 0);
rowpad = [rowpadup; rowpaddown];
padded = cell2mat(rowpad);
imshow(padded)

The black lines are the places the subsection was padded on the right or bottom.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
참고 항목
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)
