How can i pull a matrix out of matrix with indices?

2 次查看(过去 30 天)
Hi everyone. Sorry for the poor expression. I used find() function to find elements, which fulfill certain condition (non constant) . I want to have a matrix of same dimension, which contains the rest of elements in Matrix (constant) . Here is my code. But it runs incredibly long, because dimension of thisMatrix{1} is 30000 * 30000 big. How can i do this faster?
Mat_nonconst_tmp = sparse(size(thisMatrix{1}, 1), size(thisMatrix{1}, 2));
for n = 1:length(row_nonconst)
Mat_nonconst_tmp(row_nonconst(n), column_nonconst(n)) = thisMatrix{1}(row_nonconst(n), column_nonconst(n));
end
Mat_const = thisMatrix{1} - Mat_nonconst_tmp;

采纳的回答

Matt J
Matt J 2023-6-16
Do it a completely different way. Example
A=rand(5)
A = 5×5
0.1956 0.2027 0.4764 0.3016 0.3337 0.6153 0.6513 0.2582 0.3525 0.6252 0.9584 0.8762 0.8876 0.8489 0.0939 0.3990 0.3480 0.6502 0.5263 0.3498 0.6580 0.5777 0.8174 0.1849 0.9899
B=rand(5)
B = 5×5
0.9819 0.5626 0.9978 0.3930 0.7500 0.3371 0.1098 0.4372 0.7146 0.8823 0.2073 0.8749 0.0540 0.1992 0.7296 0.1819 0.4807 0.9508 0.0666 0.0887 0.6023 0.3610 0.9348 0.6361 0.9436
condition=A<0.5;
B(condition)=0
B = 5×5
0 0 0 0 0 0.3371 0.1098 0 0 0.8823 0.2073 0.8749 0.0540 0.1992 0 0 0 0.9508 0.0666 0 0.6023 0.3610 0.9348 0 0.9436

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Sparse Matrices 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by