Extracting a Column from a 4D Double Array in MATLAB using Squeeze

Click For Summary

Discussion Overview

The discussion focuses on accessing and extracting a column of values from the 4th dimension of a 4D double array in MATLAB, specifically using the `squeeze` function to reshape the output into a vector format.

Discussion Character

  • Technical explanation

Main Points Raised

  • One participant seeks to extract a column from a 4D array and save it as a new matrix.
  • Another participant points out an incorrect use of the colon operator for subscript access in MATLAB.
  • A suggestion is made to use the `squeeze` function to achieve the desired vector format from the array.
  • A later reply confirms that using `squeeze` successfully resolves the issue.

Areas of Agreement / Disagreement

Participants generally agree on the solution involving the `squeeze` function, but there is a disagreement regarding the initial use of the colon operator.

Contextual Notes

There may be limitations related to the understanding of array subscripting in MATLAB, as well as the specific behavior of the `squeeze` function in different contexts.

afallingbomb
Messages
16
Reaction score
0
Hello,

I'd like to access a column of values from the 4th dimension of a 4D Double array in MATLAB and then save them to a new matrix.

For example:

A = rand(3,3,3,3);
A(1,1,1,:)

gives me:

ans(:,:,1,1) =
0.7077

ans(:,:,1,2) =
0.0669

ans(:,:,1,3) =
0.7794

I want to create a new matrix, B, with those values but specifying B = A(1,1,1,:) results in the same output above. I want a vector in this form:

0.7077
0.0669
0.7794

Thank you!
 
Physics news on Phys.org
Your use of the colon operator is incorrect. See the Matlab docs on this subject for an explanation of how to subscript an array in the way you want.
 
Just put squeeze in front.

squeeze(A(1,1,1,:))
 
Thanks, Matonski. Squeeze does the trick!
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
8K
  • · Replies 1 ·
Replies
1
Views
9K
  • · Replies 1 ·
Replies
1
Views
21K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K