How can i decrease the execution time of a matrix classification?

I have a sparse matrix 34x2(or two column matrices of size 34).In the first column i have some double numbers and on the second column i have their id's(1-25), meaning that in both columns the non zero elements are in the same row. What i need is to create a sparse matrix 34x25 in order to classify the double numbers of the first column considering their id's.
At the moment i am using
temp1 = bsxfun(@eq,W(:,2),k);
IDClass = bsxfun(@times,temp1,W(:,1));
%where k is a vector with values 1:15
this procedure is quite costly so i need a faster way to do it but it still has to be vectorized. Any help?

 採用された回答

Steven Lord
Steven Lord 2017 年 5 月 19 日

0 投票

I'm not sure exactly what you want IDClass to look like, but I think you want something like this:
% Random data
rng(2)
A = [rand(5, 1), randperm(5).']
% Create a sparse matrix
S = sparse(1:size(A, 1), A(:, 2), A(:, 1))
% Display it as a full matrix
full(S)
If that's not what you want, can you show how you want the S generated from this A data to look?

1 件のコメント

Charis L
Charis L 2017 年 5 月 20 日
That works perfect, you are a lifesaver. Thank you for your response!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2017 年 5 月 19 日

コメント済み:

2017 年 5 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by