How to colaapse a table to reduce repeated rows?

2 ビュー (過去 30 日間)
JFz
JFz 2015 年 8 月 27 日
回答済み: JFz 2015 年 8 月 27 日
Ho,
I have a table of 6 columns. Many rows are the same. I want to collapse the same rows into one. So I use this lines to create a new table:
vMarket = 'AB';
tb='Summer';
tp = 1;
mask=strcmpi(cTblSet.VM(:),vMarket) & strcmpi(cTblSet.TB(:),tb) & (corrTblSet.TimePeriod(:) == tp);
newtable = cTblSet(mask, :);
But the newtable has 0 rows, it should have 20 rows.
The 'TimePeriod' column is all numbers. If the mask is only
mask=strcmpi(cTblSet.VM(:),vMarket) & strcmpi(cTblSet.TB(:),tb)
Then newtable has the right number of rows.
Why? Why a column of numbers are not working properly here? How to fix this problem? Thanks,
Jennifer
  1 件のコメント
Stephen23
Stephen23 2015 年 8 月 27 日
This time I formatted your code for you, but in future please do it yourself by selecting the code and clicking the {} Code button that you will find above the textbox.

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

回答 (3 件)

the cyclist
the cyclist 2015 年 8 月 27 日
The simplest way to do what you want is probably to use the unique command, with the 'rows' option.
  1 件のコメント
JFz
JFz 2015 年 8 月 27 日
Let me take a look at how to use unique. Thanks.

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


JFz
JFz 2015 年 8 月 27 日
Thanks. But still I will need the mask to break the large table into smaller tables, because there is another column that is prices which is different for every row. I want to break the large table into smaller tables, each small has the same rows for the first 3 columns but different rows has different prices.

JFz
JFz 2015 年 8 月 27 日
I guess the problem is in the '==' in the mask. When I change it to '~=', the newtable has some contents. Then why isn't "==" work?
Thanks,
Jennifer

カテゴリ

Help Center および File ExchangeSoftware Development Tools についてさらに検索

タグ

タグが未入力です。

製品

Community Treasure Hunt

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

Start Hunting!

Translated by