2 dimensional array operation

2 views (last 30 days)
Goodman
Goodman on 14 Aug 2018
Commented: Goodman on 14 Aug 2018
Index is 1000x400 logical. Current is 1000x400 double.
Array2D = Current(Index==0);
Why does Array2D have "399060x1 double" data? I expected to see 1000x400 double. How can I get "1000x400 double"?
  3 Comments
Stephen23
Stephen23 on 14 Aug 2018
Edited: Stephen23 on 14 Aug 2018
"I expected to see 1000x400 double"
The MATLAB documentation describes how array indexing works, and states that when using a logical array like you are, the "output is always in the form of a column vector." This also makes sense, because if you extract some arbitrary number of elements from an array, a vector is the only shape that is guaranteed to be able to hold them.
Goodman
Goodman on 14 Aug 2018
Thanks a lot, Stephen. I understand. That is what I was looking for

Sign in to comment.

Accepted Answer

Matt J
Matt J on 14 Aug 2018
Maybe you want
Array2D = Current.*(Index==0);
  1 Comment
Goodman
Goodman on 14 Aug 2018
Thanks. Yes, I did like you said. It worked.

Sign in to comment.

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Products


Release

R2012a

Community Treasure Hunt

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

Start Hunting!