現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
How to plot pcolor in matlab
2 ビュー (過去 30 日間)
古いコメントを表示
Hello everyone,
i want to plot pcolor plot in matlab but i tried i cannot do it. I add my data here and code also
x = [13-04-2021 00:00 13-04-2021 01:00 13-04-2021 02:00 13-04-2021 03:00 13-04-2021 04:00] like this till 14-04-2021 23:00:00
y = [10.23 11.16 12.19 13.31 14.54 15.88 17.35 18.96 20.72 22.66 24.77 27.1 29.65 32.45 35.53 38.92 42.65 46.77 51.32]
z = [2.27E+03 3.94E+03 4.48E+03 6.26E+03 3.18E+03 3.78E+03 5.37E+03 5.60E+03 6.35E+03 8.47E+03 1.05E+04 1.05E+04
1.36E+04 1.12E+04 8.48E+03 3.96E+03 5.84E+03 4.55E+03 3.65E+03 6.17E+03 7.48E+03 6.98E+03 9.84E+03 1.11E+04
5.72E+04 6.90E+04 5.64E+04 4.71E+04 1.94E+04 6.37E+03 6.59E+03 6.89E+03 8.81E+03 9.70E+03 8.11E+03 9.59E+03
1.26E+04 1.34E+04 1.69E+04 1.99E+04 2.18E+04 2.62E+04 2.98E+04 9.09E+03 5.16E+03 8.73E+03 3.96E+03 4.95E+03
5.16E+03 4.06E+03 4.24E+03 6.17E+03 7.99E+03 8.20E+03 6.68E+03 1.07E+04 1.24E+04 1.36E+04 1.78E+04 1.89E+04]
my x data is in one range and y is in another range and my z data is in different size range.
how to plot that graph?
i hope i will get the answer for this thank you in advance.
[x,y] = meshgrid(x,y);
Pcolor(x,y,z);
5 件のコメント
Rik
2021 年 12 月 9 日
You need to find a way to match up your data. It is not clear to me how you are planning to do that. How are you making sure you have as many z values as you have x-y-combinations?
Walter Roberson
2021 年 12 月 9 日
xd = {'13-04-2021 00:00' '14-04-2021 23:00'};
xdt = datetime(xd, 'InputFormat', 'dd-MM-yyyy HH:mm');
x = xdt(1) : hours(1) : xdt(2);
y = [10.23 11.16 12.19 13.31 14.54 15.88 17.35 18.96 20.72 22.66 24.77 27.1 29.65 32.45 35.53 38.92 42.65 46.77 51.32];
z = [2.27E+03 3.94E+03 4.48E+03 6.26E+03 3.18E+03 3.78E+03 5.37E+03 5.60E+03 6.35E+03 8.47E+03 1.05E+04 1.05E+04
1.36E+04 1.12E+04 8.48E+03 3.96E+03 5.84E+03 4.55E+03 3.65E+03 6.17E+03 7.48E+03 6.98E+03 9.84E+03 1.11E+04
5.72E+04 6.90E+04 5.64E+04 4.71E+04 1.94E+04 6.37E+03 6.59E+03 6.89E+03 8.81E+03 9.70E+03 8.11E+03 9.59E+03
1.26E+04 1.34E+04 1.69E+04 1.99E+04 2.18E+04 2.62E+04 2.98E+04 9.09E+03 5.16E+03 8.73E+03 3.96E+03 4.95E+03
5.16E+03 4.06E+03 4.24E+03 6.17E+03 7.99E+03 8.20E+03 6.68E+03 1.07E+04 1.24E+04 1.36E+04 1.78E+04 1.89E+04];
size(x)
ans = 1×2
1 48
size(y)
ans = 1×2
1 19
size(z)
ans = 1×2
5 12
Your data is all different sizes; we cannot test with it, and we cannot figure out what you are trying to do.
vignesh mohan
2021 年 12 月 9 日
Hello walter roberson i had attached some reference plot which one i need to try out using this data. I need my x data will come in x-axis and in my y-axis i need my y data from 10 to 50 and my z-axis my z data will come and matrix format.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/828400/image.jpeg)
vignesh mohan
2021 年 12 月 9 日
Hello Rik i had attached reference graph just have a look then you will get some idea
vignesh mohan
2021 年 12 月 9 日
Hello Walter sir i had attached some sample data sheet also. my column name should come in my y-axis date will come in my x-axis remaining all will come in z-axis.
i hope you will help me to come out from this sir i tired many way.
Thank you
回答 (1 件)
Walter Roberson
2021 年 12 月 9 日
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/828415/Book1.xlsx';
T = readcell(filename);
x = [T{2:end,1}];
y = cell2mat(T(1,2:end));
z = cell2mat(T(2:end,2:end));
surf(x, y, z.', 'edgecolor', 'none');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/828480/image.png)
20 件のコメント
vignesh mohan
2021 年 12 月 9 日
Hai sir I tried but it shows undefined function or variable 'readcell'. I am using R2016a matlab
vignesh mohan
2021 年 12 月 9 日
Hai sir I tried T = xlsread(Book1) but it shows error message. Error using xlsread (line 125) File name must be a string
Rik
2021 年 12 月 9 日
Book1 = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/828415/Book1.xlsx';
%this line is only required if you're downloading the file, instead of
%using a local copy
Book1=websave('Book1.xlsx',Book1);
T = xlsread(Book1)
T = 85×20
1.0e+05 *
NaN 0.0001 0.0001 0.0001 0.0001 0.0001 0.0002 0.0002 0.0002 0.0002 0.0002 0.0002 0.0003 0.0003 0.0003 0.0004 0.0004 0.0004 0.0005 0.0005
0.4431 0.0151 0.0091 0.0224 0.0156 0.0176 0.0182 0.0349 0.0275 0.0350 0.0307 0.0407 0.0434 0.0530 0.0514 0.0627 0.0736 0.0653 0.0668 0.0679
0.4431 0.0284 0.0228 0.0224 0.0198 0.0248 0.0204 0.0250 0.0293 0.0350 0.0489 0.0350 0.0401 0.0505 0.0486 0.0641 0.0668 0.0708 0.0680 0.0634
0.4431 0.0284 0.0243 0.0286 0.0282 0.0186 0.0212 0.0297 0.0269 0.0238 0.0316 0.0320 0.0428 0.0506 0.0476 0.0574 0.0607 0.0683 0.0654 0.0613
0.4431 0.0132 0.0136 0.0212 0.0187 0.0230 0.0258 0.0256 0.0292 0.0345 0.0356 0.0379 0.0474 0.0501 0.0550 0.0608 0.0634 0.0653 0.0762 0.0631
0.4431 0.0290 0.0263 0.0266 0.0250 0.0236 0.0340 0.0262 0.0310 0.0284 0.0318 0.0448 0.0415 0.0400 0.0548 0.0479 0.0628 0.0604 0.0693 0.0702
0.4431 0.0398 0.0349 0.0473 0.0260 0.0274 0.0342 0.0430 0.0362 0.0311 0.0369 0.0283 0.0477 0.0422 0.0572 0.0577 0.0659 0.0640 0.0640 0.0718
0.4431 0.0170 0.0182 0.0149 0.0093 0.0204 0.0251 0.0236 0.0263 0.0233 0.0261 0.0385 0.0418 0.0479 0.0545 0.0543 0.0587 0.0628 0.0654 0.0660
0.4431 0.0208 0.0288 0.0099 0.0229 0.0123 0.0181 0.0303 0.0288 0.0335 0.0389 0.0406 0.0340 0.0482 0.0491 0.0525 0.0542 0.0564 0.0611 0.0685
0.4431 0.0132 0.0152 0.0224 0.0156 0.0257 0.0235 0.0336 0.0217 0.0310 0.0375 0.0367 0.0398 0.0448 0.0481 0.0489 0.0546 0.0592 0.0676 0.0619
vignesh mohan
2021 年 12 月 9 日
When I entered y=cell2mat(T(1,2:end));it shows error message Error using cell2mat (line42) You cannot subscript a table using only one subscript. Table subscripting requires both row and variable subscrpts. I don't know next what I have to do ????
Image Analyst
2021 年 12 月 9 日
Book1 needs to be a string, and apparently it's not. Try
fullFileName = fullfile(pwd, 'Book1.xlsx');
if isfile(fullFileName)
[numbers, strings, T] = xlsread(fullFileName);
else
warningMessage = sprintf('File not found:\n%s', fullFileName);
uiwait(errordlg(warningMessage));
return;
end
T will be the raw cell array while numbers is just the numbers (with nan wherever there is a string in the matrix), and strings is a cell array with just the text cells.
vignesh mohan
2021 年 12 月 9 日
I tried sir but it shows Undefined function 'isfile' for input arguments of type 'char'
Image Analyst
2021 年 12 月 9 日
You must have a really old version. Use exist() instead:
if exist(fullFileName, 'file')
vignesh mohan
2021 年 12 月 10 日
Thank you Image Analyst
when i entered surf(x, y, z.', 'edgecolor', 'none'); it show errow message.
Error using matlab.graphics.chart.primitive.Surface/set
Invalid parameter/value pair arguments.
Error in matlab.graphics.chart.internal.ctorHelper (line 6)
set(obj, pvpairs{:});
Error in matlab.graphics.chart.primitive.Surface
Error in surf (line 126)
hh = matlab.graphics.chart.primitive.Surface(allargs{:});
The above Error message is pop up.
vignesh mohan
2021 年 12 月 10 日
Full code i showed you
T = Book1;
fullFileName = fullfile(pwd, 'Book1.xlsx');
if exist(fullFileName, 'file')
[numbers, strings, T] = xlsread(fullFileName);
else
warningMessage = sprintf('File not found:\n%s', fullFileName);
uiwait(errordlg(warningMessage));
return;
end
x = [T{2:end,1}];
y = cell2mat(T(1,2:end));
z = cell2mat(T(2:end,2:end));
surf(x, y, z.', 'edgecolor', 'none');
Now i am standing in last line of the code. Help me to figure it out. Thank you so much i advance.
vignesh mohan
2021 年 12 月 10 日
Hai sir
Again i got same error
Error using matlab.graphics.chart.primitive.Surface/set
Invalid parameter/value pair arguments.
Error in matlab.graphics.chart.internal.ctorHelper (line 6)
set(obj, pvpairs{:});
Error in matlab.graphics.chart.primitive.Surface
Error in surf (line 126)
hh = matlab.graphics.chart.primitive.Surface(allargs{:});
vignesh mohan
2021 年 12 月 10 日
編集済み: Walter Roberson
2021 年 12 月 11 日
T = Book1;
fullFileName = fullfile(pwd, 'Book1.xlsx');
if exist(fullFileName, 'file')
[numbers, strings, T] = xlsread(fullFileName);
else
warningMessage = sprintf('File not found:\n%s', fullFileName);
uiwait(errordlg(warningMessage));
return;
end
x = [T{2:end,1}];
y = cell2mat(T(1,2:end));
z = cell2mat(T(2:end,2:end));
surf(x, y, z.');
Error Message
Error using matlab.graphics.chart.primitive.Surface/set
Invalid parameter/value pair arguments.
Error in matlab.graphics.chart.internal.ctorHelper (line 6)
set(obj, pvpairs{:});
Error in matlab.graphics.chart.primitive.Surface
Error in surf (line 126)
hh = matlab.graphics.chart.primitive.Surface(allargs{:});
This is my current code sir
Till z the code went good i think i didnt receive any Error message
But when i enter Surf code i got the error
Walter Roberson
2021 年 12 月 11 日
The code works when I try it in R2016a on my system.
To debug this, give the commands
dbstop in matlab.graphics.chart.internal.ctorHelper
surf(x, y, z.')
The code should run, but stop in ctorHelper.m . When it stops, please show us the value of the variable named pvpairs -- and also please show us class(obj)
vignesh mohan
2021 年 12 月 13 日
Hai sir,
pvpairs show ['Parent' 1x1 Axes
'''21-04-202121-04-2021 00:15:0021-04-2021 00:30:0021-04-2021 00:45:0021-04-2021 01:00:0021-04-2021 01:15:0021-04-2021 01:30:0021-0...'' <Preview truncated at 128 characters>' 1x19 double
19x84 double]
obj shows 1 x 1 Surface
After entered surf(x,y,z.') it shows below code
5 if ~isempty(pvpairs)
K>>
vignesh mohan
2021 年 12 月 13 日
編集済み: Walter Roberson
2021 年 12 月 13 日
Function:
function ctorHelper(obj, pvpairs)
% Copyright 2014-2015 The MathWorks, Inc.
if ~isempty(pvpairs)
set(obj, pvpairs{:});
end
end
Walter Roberson
2021 年 12 月 13 日
Please show the output for
which -all surf
Your pvpairs are not even in the same order that I would expect for your release. I would expect
'XData' [1x84 double] 'YData' [1x19 double] 'ZData' [19x84 double] 'Parent' [1x1 Axes]
vignesh mohan
2021 年 12 月 13 日
>> surf(x, y, z.')
5 if ~isempty(pvpairs)
K>> which -all surf
C:\Program Files\MATLAB\R2016a\toolbox\matlab\graph3d\surf.m
C:\Program Files\MATLAB\R2016a\toolbox\mbc\mbctools\@sweepset\surf.m % Shadowed sweepset method
K>>
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/832710/image.jpeg)
It came like this Sir.
once when i entered above code, it will remove all x,y,z values from my workspace and shows only obj,pvpairs.
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
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)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)