separate column into several using descriptive variable

I would like to split up a cell array that I have using a grouping variable. I have not found an applicable group function. I have a column of numbers say x = 123456789 and y = c1 c2 c1 c3 c4 c3 c1 c3 c4 I would like to split it up into 4 separate arrays with the values from x. Any help would be greatly appreciated. I have about 10 000 samples so manually going through would not be an option.
Cheers

4 件のコメント

Stephen23
Stephen23 2016 年 1 月 25 日
It sounds like you need to use some indexing to pick those.
But your explanation is not very clear: please edit your question and provide us with exact input and output arrays for us to try out. How is x = 123456789 a "column of numbers"? x is a scalar numeric. What are x and y? What is the input that will be used to pick these columns?
Brandon MacKinnon
Brandon MacKinnon 2016 年 1 月 25 日
[ndata, text, alldata] = xlsread('step1g.xls','step1g'); text(1,:) = [];
fbp = text(:,3); height = ndata(:,4);
that is my code. I have the heights that I need to separate out by group, which is in fbp. I want to sub divide fbp so I have separate arrays so that I can do statistics and transformations on each group individually.
Image Analyst
Image Analyst 2016 年 1 月 25 日
I'm just as confused as Stephen. It doesn't look like Brandon has read this yet. Like Stephen says, x = 123456789 means x is a single number, not a column of numbers. So when you say "values from x", what values would those be? There is only one value and that is 123456789. What are the other values???????????????????
And assuming the c in your definition of y means column, I can't see any pattern to the numbers in y, either by themselves or by looking at x. What is the rule for assembling y like that???
Brandon MacKinnon
Brandon MacKinnon 2016 年 1 月 25 日
My Mistake, my MATLAB terms are not correct.
I have height data here: height = ndata(:,4);
then i have a grouping variable here fbp = text(:,3);
both have 10 000 rows and one column
I would like to extract the rows from height using a grouping variable in fbp

回答 (1 件)

jgg
jgg 2016 年 1 月 25 日
編集済み: jgg 2016 年 1 月 25 日

0 投票

You want the discretize function:
x = 100*rand(1000,1); %your data
groups = [0:10:100]; %your bins to group the data into
group_id = discretize(x,bins);
If you don't have groups and want every unique value of x instead, try unique instead with the third return option.

3 件のコメント

Brandon MacKinnon
Brandon MacKinnon 2016 年 1 月 25 日
group_id = discretize(x,groups);
Undefined function 'discretize' for input arguments of type
'double'.
that is the error i get with that code? I have about 7 different groups i need to sort into.
jgg
jgg 2016 年 1 月 25 日
This code works fine for me. What are you calling that it giving you the error exactly? Are you using an older version of Matlab?
The documentation is here:
jgg
jgg 2016 年 1 月 25 日
If you have an older version of Matlab this should work instead:
x = 100*rand(1000,1); %your data
groups = [0:10:100]; %your bins to group the data into
[~,group_id] = histc(x,groups);

この質問は閉じられています。

質問済み:

2016 年 1 月 25 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by