There are two lines of code in someone's script that I can't figure out how it works. Here is the code and attached is a .mat file with the variables themselves. Note that the .mat file begins with the original regionMat_m, and once you run the code regionMat_m changes.
bar = tmp(rnum(1:rc));
regionMat_m = reshape(bar(regionMat_m),R,C);
bar and regionMat_m have conflicting sizes of 1x156 and 256x400 respectively, so I'm not sure how bar(regionMat_m) even compiles. Once it does compile, I don't see the correlation between the output and the input. Help would be much appreciated!
Sidenote: I know bar is also a MATLAB function for graphing. I don't know why the variable is named bar. I didn't write this code! Just trying to figure out what is going on.

 採用された回答

Matt J
Matt J 2023 年 8 月 29 日
編集済み: Matt J 2023 年 8 月 29 日

1 投票

There is no requirement that an index array be the same size as the array being indexed. Example:
values=[20,30,40]
values = 1×3
20 30 40
values(ones(5))
ans = 5×5
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品

リリース

R2022b

質問済み:

2023 年 8 月 29 日

編集済み:

2023 年 8 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by