3D surface plot from imported 2D excel array
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
New to Matlab. Im sure this is answered somewhere already, but I can't manage to find it; I have a 2D array of experimental data tabulated in excel. 1st row and column are varied parameters, and I measure the corresponding amplitudes in the matrix. Importing the table to Matlab is simple. I would then like to plot a 3D surface of the 1st row (x) vs. 1st column (y), for the amplitudes in the matrix. This is very straightforward in excel, but the plots look terrible. Thanks in advance for the help.
採用された回答
Star Strider
2018 年 3 月 2 日
Try this:
[D,S,R] = xlsread('ExampleArray.xls');
figure(1)
ribbon(D(:,1), D(:,2:end))
grid on
[X,Y] = meshgrid((1:size(D,2)-1), D(:,1));
Z = D(:,2:end);
figure(2)
surf(X, Y, Z)
grid on
8 件のコメント
Hi Star Strider, Thanks for the help! This is pretty close to what I am after. However, I still have a couple issues with the result. The x axis looks correct (first column of the table), but the y axis is from 1 to 5, and not the values in the first row of the table. Also the colormap is not correct. I tried this, but the colormap scaling is apparently not being automatically adjusted;
[D,S,R] = xlsread('ExampleArray.xls');
[X,Y] = meshgrid((1:size(D,2)-1), D(:,1));
Z = D(:,2:end);
figure(2)
C=X.*Y;
surf(X,Y,Z)
colormap parula
shading interp
colorbar
As always, my pleasure.
The first value in the first row is NaN, and that will cause problems. That is the reason I chose [1:5] to test the code. The first column is also significantly different from the others, and since I have no idea what the data are, I used it for the independent variable.
You can get some color definition by adding:
caxis([0.001 0.025])
after the surf call. (No magickal knowledge to that — I experimented until I found something that worked!)
joe pearson
2018 年 3 月 2 日
The caxis function worked nicely. It seems the amplitude of the Z data was too low for the colormap to rescale properly by default. I still haven't come up with a good way to rescale the x axis. It is actually the y axis that is being set correctly already (The 1st column of the data table). You are right they are the independent variable. The second independent variable, x, is the 1st row (wavelengths in this case). The Z amplitudes are the measured values in the rest of the table for the corresponding x,y settings. It seems like there should be a very straightforward way to deal with this, but I haven't managed to figured it out yet. Any help would be greatly appreciated.
Star Strider
2018 年 3 月 2 日
The first element in the first row is NaN.
What should that wavelength be?
joe pearson
2018 年 3 月 2 日
Yes, the way the data is generated in the excel file it is not supposed to be a number. The 1st row basically contains the column headings for the z data below, and the 1st column is the row headings. The y-axis looks correct (4000 to 6000 increments), but the 1-5 on the x axis should instead be the wavelengths 825-945 in the table.

I’m glad caxis works!
So perhaps:
Row_1 = linspace(825, 945, 5);
Would that do what you want?
joe pearson
2018 年 3 月 3 日
編集済み: joe pearson
2018 年 3 月 3 日
That's almost what I wanted. I finally figured out how it works. Thanks again for all the help!! This is the code I am using, in case the next person to come along finds it useful;
[D,S,R] = xlsread('ExampleArray.xls');
Z = D(2:end,2:end);
M = max(max(Z));
figure(1)
X = D(1,2:end);
Y = D(2:end,1);
x1 = min(X);
x2 = max(X);
y1 = min(Y);
y2 = max(Y);
surf(X,Y,Z)
axis manual
xlim([x1 x2])
ylim([y1 y2])
colormap parula
shading interp
colorbar
caxis([0 M])
%view(2)

uncommenting the view(2) makes a nice psuedo 3D view
Star Strider
2018 年 3 月 3 日
As always, my pleasure!
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Creating, Deleting, and Querying Graphics Objects についてさらに検索
参考
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)
