フィルターのクリア

Histogram won't plot decimals

7 ビュー (過去 30 日間)
Sclay748
Sclay748 2020 年 8 月 19 日
コメント済み: Adam Danz 2020 年 8 月 21 日
Hello, This is a screenshot of a table I have constructed for work.
Just to play it safe, I blacked out the column names, though it would be hard to assume anything with just 7 rows of the table to go off of. We will call the 5 fields "column1, column2, etc."
If I do:
histogram([a(1:135756).column1])
It creates a histogram wilth all 135,756 points. Works beautifully.
If I do:
histogram([a(1:135756).column4])
I get an error saying "x must be a numeric column vector."
I assume it has something to do with those symbols next to where I wrote "1, 2, 3, 4, 5" in each column. I don't know what each of them mean. Column 4 and 5 are not the same as 1, 2, & 3 because they include decimals, therefore a histogram of column 1 and 2 work great, but 4 and 5 produce that error.
How would I fix this so I can do a histogram of column 4 and 5, with decimals.
Thanks!

採用された回答

Steven Lord
Steven Lord 2020 年 8 月 19 日
What does this command display?
class([a(1:135756).column4])
My guess is that it will probably display something like char or string rather than double or single.
  7 件のコメント
Sclay748
Sclay748 2020 年 8 月 20 日
Another question, using the same table as above. How would I do the mean of a column?
I did:
x = mean(a.column1)
but it says too many input arguments.
Usually I have no problem with using mean, but is it possisble that this is just too big of a set of data?
Steven Lord
Steven Lord 2020 年 8 月 20 日
You don't have a table array. You have a non-scalar struct array.
When you write a.column1 for a non-scalar struct a it makes a comma-separated list.
a = struct('column1', {1, 2:3, 4:6}) % Makes a 3 element struct
a.column1
Note that the second line displays three separate ans values. For your struct array with 135k elements, that expression would display 135k separate ans values, and if you wrote:
mean(a.column1)
that's the equivalent of:
mean(1, 2:3, 4:6)
mean doesn't have a syntax that matches that particular combination of inputs. It certainly doesn't have a syntax that accepts 135k inputs!
Concatenate the elements of that comma-separated list together and pass that vector into mean.
x1 = [1, 2:3, 4:6]
x2 = [a.column1]
mean(x2)
mean([a.column1])

サインインしてコメントする。

その他の回答 (1 件)

Adam Danz
Adam Danz 2020 年 8 月 19 日
編集済み: Adam Danz 2020 年 8 月 19 日
The problem is likely caused by at least one of the elements in column 4 that is not numeric. The non-numeric value could be part of the actual raw data or it could be an artifact created when the data are read into Matlab. The symbols you pointed out indicate that the columns have mixed data types.
Here's a demo that illustrates the problem.
a(1).c = 1.234;
a(2).c = pi;
a(3).c = '0'; % Note, this is not numeric
a(4).c = 2.814;
a(5).c = {0}; % Note, this is not numeric
When those values are concatenated, they are clearly not numeric,
[a.c]
ans =
1×5 cell array
{[1.2340]} {[3.1416]} {'0'} {[2.8140]} {[0]}
which causes the error
histogram([a.c])
Error using histogram
Expected input number 1, x, to be one of these types:
double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64, logical, datetime, duration
Instead its type was cell.
or
[a(1:4).c]
which causes the error
histogram([a(1:4).c])
Error using histogram>parseinput (line 300)
Trailing input arguments must occur in name-value pairs.
The error message you shared, "x must be a numeric column vector", is odd for your Matlab release (r2020a). As you can see in the error message above, the x-input to histogram can be non-numeric (ie, datetime, duration, logical, etc.). Seeing the full error message and the entire line that calls histrogram() would be helpful. It would also be helpful to see the first few elements of the output to a(1:135756).column4.
  8 件のコメント
Sclay748
Sclay748 2020 年 8 月 20 日
Another question, using the same table as above. How would I do the mean of a column?
I did:
x = mean(a.column1)
but it says too many input arguments.
Usually I have no problem with using mean, but is it possisble that this is just too big of a set of data?
Adam Danz
Adam Danz 2020 年 8 月 21 日
Looks like Steven Lord addressed your question.

サインインしてコメントする。

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by