現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
i have a data of 2 columns
d= [12] 'A'
[23] 'B'
[18] 'H'
d1=[23 45]
out = [d1, d(ismember(d(:,1),d1(:,1),'rows'),1:end)]
if i do this i get error
Input must be cell arrays of strings
please help
採用された回答
Sven
2011 年 11 月 15 日
Hi FIR,
The error comes because the ismember() function expects either a matrix of numbers or a cell array of strings. Since d is a cell, you provided a cell array of numbers which is unfortunately invalid. Try converting to numbers like the following:
dMask = ismember(cell2mat(d(:,1)), d1);
Secondly, you were trying to concat d1 (which is a 1x2 matrix) with various rows of a cell (ie, an nx2 cell):
out = [d1, d(dMask,:)]
This won't work on two counts:
1. Cells won't concat with matrices - one of them needs to be converted.
2. d1 is 1x2, which won't concat if your result has more than 1 rows.
------
So, I've updated my answer as below from the comments you made. Firstly, we have your inputs d and d1 as follows:
d = {12 'A'; 23 'B'; 18 'H'; 12 'P'};
d1 = [23 45;18 10];
And what you actually want to do is concat d1 with its corresponding indices into d. Note that this means you're asking which entries in the first column of d1 are members of the first column of d... Note that this is the opposite ordering from your original question, but it seems more logical. Try the following two lines, I think that they answer your question:
[dMask, indices] = ismember(d1(:,1), cell2mat(d(:,1)));
[num2cell(d1(dMask,:)) d(indices,2)];
Does this help?
12 件のコメント
FIR
2011 年 11 月 16 日
sven please suggest .assuming that d1 has more rows
for example d has 4000 rows and 62 column,d has 10 rows
FIR
2011 年 11 月 16 日
Sven i get an error wen executing ur command
Error using ==> cell2mat
Too many input arguments.
Error in ==> qq at 8
dMask = ismember(cell2mat(d(:,1), d1));
Sven
2011 年 11 月 16 日
So answer this:
A = [1 2];
B = [10 20; 15 40];
Here "A" has 1 row, "B" has 2 rows. Please clarify what your final answer would look like if you combined A and B.
Sven
2011 年 11 月 16 日
Oh, sorry, there was a typo: I missed a ")". It's fixed now
FIR
2011 年 11 月 16 日
but sven ur A and B data is wrong
from my dat d and d1
i need output as
23 45 B
if
data is
d= [12] 'A'
[23] 'B'
[18] 'H'
[12] 'P'
d1=[23 45;18 10]
but sven ur A and B data is wrong
from my dat d and d1
i need output as
23 45 B
if
data is
d= [12] 'A'
[23] 'B'
[18] 'H'
[12] 'P'
d1=[23 45;18 10]
i NEED OUTPUT AS
23 45 B
18 10 H
Sven
2011 年 11 月 16 日
Answer updated. What do you think?
FIR
2011 年 11 月 16 日
THANKS A LOT Sven,this is what i was expecting
FIR
2011 年 11 月 16 日
Another one question I have 4000 rows and 5 columns I have to divide this data into 5 groups so that i will have 800 rows and 25 columns,plz help
Sven
2011 年 11 月 16 日
If the question's answered, hit accept :)
Does the following do what you wanted?
MAT_4000by5 = rand(4000,5);
MAT_800by25 = reshape(MAT_4000by5,800,25);
FIR
2011 年 11 月 16 日
Thanks Sven i have 2 more questions ,
I have 5 columns and 800 rows and the last row contains percentage ranging from (90.20 to 99.98),first i want to round off that percentage ans have to display it withs all its column and ten i want to select two percentage which is highest and want to dispaly with all its 5 columns
output must be
1 3 1 0 99
2 3 1 0 98
next i want to find five fold crodd validation error for the third column,by using in built function,please help
Sven
2011 年 11 月 16 日
I'm a bit lost on what you want to do here, and it seems quite a different topic to the original question. I suggest hitting "accept" to the original question, and then asking a new question specifically about "how to format rows columns for display". If you can make a short example showing exactly the input you have and the output you want, I'm sure it will get a clear answer.
FIR
2011 年 11 月 16 日
Sven u have not answered to my question
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Resizing and Reshaping Matrices についてさらに検索
タグ
参考
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)
