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
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
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!

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by