필터 지우기
필터 지우기

Error using gscatter. There must be one value of G for each row of X.

조회 수: 20 (최근 30일)
Zhou Ci
Zhou Ci 2023년 3월 10일
편집: Zhou Ci 2023년 3월 13일
Hi,
I am trying to make a figure of 3 variables. As per description of gscatter, length of x and y vectors should be same (in my code it's same). My g here is mean of each bin. Here is my code:
Data1=readtable('F:\Excel_file\Results.xlsx', 'Sheet', 1, 'ReadVariableNames', true, 'VariableNamingRule','preserve');
Data = table2array(Data1)
Y = Data(:,1); 5000x1 double
X = Data(:,2); 5000x1 double
edges = 0:10:40;
Coarseaer_Bin=discretize(Data1.aer,edges);
%Find the mean, Std for each bin
fnstdMn=@(x)std(x)./sqrt(size(x,1));
tStats=grpstats(Data,'Coarseaer_Bin',{'mean','std',fnstdMn});
tStats.Properties.VariableNames=strrep(tStats.Properties.VariableNames,'Fun3','stdMn');
% plot the data
g = gscatter(X,Y,tStats.mean_Coarseaer_Bin)
When I try to plot it gives me error, 'There must be one value of G for each row of X'. I don't know what I'm missing here. Any help would be appreciated. Thank you

답변 (1개)

Walter Roberson
Walter Roberson 2023년 3월 10일
tStats=grpstats(Data,'Coarseaer_Bin',{'mean','std',fnstdMn});
tStats.Properties.VariableNames=strrep(tStats.Properties.VariableNames,'Fun3','stdMn');
Those calls and assignments in that form are only valid when Data is a table. However
Data = table2array(Data1);
so Data is not a table.
You would not reach the gscatter because of those errors.
If your actual code is processing Data1 instead of Data, then the result mean that you get out would be a mean per group, not a mean per row of input. But you gscatter specifying the means as the group variable. When you use gscatter then the group input parameter must effectively be the class number or class label for each row.
  댓글 수: 3
Zhou Ci
Zhou Ci 2023년 3월 10일
Secondly if gscatter doesn't work here. Is there any other function which I can use here? I have X and Y vectors of the same length and in the figure I want to plot the mean of each bin of my 3rd variable (Data1.aer here).
Walter Roberson
Walter Roberson 2023년 3월 10일
You have (implicitly) a bin number for each bin. That can be the group number of gscatter purposes.
You have a mean Coarseaer_Bin for each of the bins. That could be one of the two variables (X or Y)
You need a second variable for scatter purposes. I do not know what you would use for that.
If you were to take mean X and mean Y for the bin, that would be two variables, and then how would you represent mean Coarseaer_Bin ? Spot size? Color? Different marker shape for each bin and the marker color encodes intensity of mean Coarseaer_Bin ??
I wonder if you should be looking at using boxplot ?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by