PLOT ARRAY OF SURF PLOTS IN ONE PLOT
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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 件のコメント
OLUWAFEMI AKINMOLAYAN
2022 年 6 月 17 日
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?
Walter Roberson
2022 年 6 月 19 日
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.
OLUWAFEMI AKINMOLAYAN
2022 年 6 月 19 日
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 についてさらに検索
参考
2022 年 6 月 16 日
2022 年 6 月 23 日
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
