Replacing cell values based on reference file

1 回表示 (過去 30 日間)
Abin Kuruvilla Mathew
Abin Kuruvilla Mathew 2020 年 12 月 22 日
回答済み: Vinai Datta Thatiparthi 2020 年 12 月 28 日
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
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!

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by