フィルターのクリア

Matrix combining with array in a specific manner

1 回表示 (過去 30 日間)
Ahsan Khan
Ahsan Khan 2012 年 6 月 7 日
Hello MATLABERS,
how do i combine a array of integers with a Matrix of Integers. ex: Matrix A = [1 2 3 4 5 6 7 8 9 10] is combined with a matrix B = [2 5 7;1 2 9 ;4 5 6] in such a way that the resultant matrix C results should be as follows: so if a sequence has a one in it, it is stored right under one==>
[1 2 3 4 5 6 7 8 9 10;0 2 0 0 5 0 7 0 0 0;1 2 0 0 0 0 0 0 9 ;0 0 0 4 5 6 0 0 0]
1 2 3 4 5 6 7 8 9 10
0 2 0 0 5 0 7 0 0 0
1 2 0 0 0 0 0 0 9 0
0 0 0 4 5 6 0 0 0
P.s if ur interested in only a scalar combined with a matrix a quick solution was posted by Wayne King http://www.mathworks.com/matlabcentral/answers/40436-matrix-filling

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 6 月 7 日
i1 = arrayfun(@(ii)ismember(A,B(ii,:)),(1:size(B,1)),'un',0);
out = ones(size(B,1),1)*A.*cat(1,i1{:});
or
out = bsxfun(@times,cat(1,i1{:}),A)
This is a replay of question
  2 件のコメント
Ahsan Khan
Ahsan Khan 2012 年 6 月 7 日
thanks a MIL...works like a charm. but now that im trying to store the reults to a excel file im getting an error:
xlswrite('Result.xls',out);
the error im getting is...
Error using xlswrite (line 220)
Invoke Error, Dispatch Exception:
Source: Microsoft Excel
Description: Microsoft Excel cannot access the
file 'C:\Program Files\MATLAB\R2012a\bin\'.
There are several possible reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the
same name as a currently open workbook.
Help File: xlmain11.chm
Help Context ID: 0
Error in Prac (line 8)
xlswrite('Result.xls',out)
Andrei Bobrov
Andrei Bobrov 2012 年 6 月 7 日
Choose other directory for the 'Result.xls' (non 'C:\Program Files\MATLAB\R2012a\bin\')

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStandard File Formats についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by