Replacing cell values based on reference file
1 view (last 30 days)
Show older comments
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 Comment
Ive J
on 22 Dec 2020
Please show what you've done so far, and the exact bottlenecks you are facing with. An example would be nice!
Answers (1)
Vinai Datta Thatiparthi
on 28 Dec 2020
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 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!