Replacing cell values based on reference file
1 次查看(过去 30 天)
显示 更早的评论
Hi
I have a reference matrix (.mat file, 68x68) with values between 0 and 1. And have similar matrices n = 29, for which I will need to replace the cell values to '0' based on the reference matrix and leave rest of the cells (off the 29 matrices) as it is????
Does anyone know how to code this?
Highly appreciate it
akm
1 个评论
Ive J
2020-12-22
Please show what you've done so far, and the exact bottlenecks you are facing with. An example would be nice!
回答(1 个)
Vinai Datta Thatiparthi
2020-12-28
Hi Abin,
.."I will need to replace the cell values to '0' based on the reference matrix"...
From your description, it's unclear what is the logic that you're using to determine which "cells" in the matrices are set to 0 and which aren't. So, I'm assuming a simple threshold like 0.5 to determine the values across all the matrices. (This is an assumption, consider modifying this part of the algorithm accordingly to suit your use-case).
.."And have similar matrices n = 29"...
In order to iterate through these 29 matrices, two ways that could be useful are:
1) Put together all these 29 matrices into a single 3-D matrix to get a 68x68x3 matrix
(OR)
2) Create a cell array whose individual values are each of the 29 matrices
For example,
% Option 1
for idx=1:numel(referenceMatrix) % Reference Matrix
if (referenceMatrix(idx) < 0.5) % Threshold
[r, c] = ind2sub(size(referenceMatrix), idx); % Convert index to subscript
concatenatedMatrix(r,c,:) = 0; % Replace specific cell across all 29 matrices to 0
end
end
You could do take a similar approach with Option 2 as well.
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!