Replacing cell values based on reference file

1 view (last 30 days)
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
  1 Comment
Ive J
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!

Sign in to comment.

Answers (1)

Vinai Datta Thatiparthi
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
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
You could do take a similar approach with Option 2 as well.
Hope this helps!

Community Treasure Hunt

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

Start Hunting!

Translated by