Trying to Iterate Through MultiDimensional Matrix

Hello all! I am trying to iterate through a multi-dimensional matrix which is in a separate .mat file in order to use mathetmatical operations on certain values which meet required parameters. What is the process of iterating through each value in this file called A to check if each individual number meets these certain requirements?
Thanks!

回答 (1 件)

Image Analyst
Image Analyst 2018 年 12 月 16 日

0 投票

If you can get the matrix from the .mat file, like
s = load(filename); % Load file into structure.
m = s.m; % Extract matrix m from the structure s.
then you can create a mask. For example to find indexes of all values of m greater than 9:
mask = m > 9; % A logical vector.
Then you can do the operation vectorized without having to iterate over it.
For example, let's say you want to take the square root of the values greater than 9. You'd do
m(mask) = sqrt(m(mask));
Take note that the mask (which is a logical vector) must show up on both sides of the operation to make sure that the values not meeting the criteria are operated on.

カテゴリ

ヘルプ センター および File ExchangeAuthor Block Masks についてさらに検索

質問済み:

2018 年 12 月 16 日

回答済み:

2018 年 12 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by