4

I currently have:

val(:,:,1) =

    0.7216

val(:,:,2) =

    0.7216

val(:,:,3) =

    0.7216

But I want

0.7216, 0.716, 0.721.

What sort of operation can I do to do that?

NullVoxPopuli
  • 61,906
  • 73
  • 206
  • 352
  • The numbers you want don't actually match the values in val, is this a mistake or is there some other processing required. – Adrian Jan 18 '11 at 12:39
  • possible duplicate of [How do I resize a matrix in MATLAB?](http://stackoverflow.com/questions/793574/how-do-i-resize-a-matrix-in-matlab) – gnovice Jan 18 '11 at 14:21
  • Agreed similar question but subtle differences, the mentioned duplicate is talking about reshaping a matrix, whereas this is more about removing dimensions. OK you can argue it's the same thing but for anyone searching for an answer they are likely to be asking slightly different questions so may not find the resize question. Perhaps the duplicate question could be updated to cover "both" scenarios. – Adrian Jan 19 '11 at 10:46

3 Answers3

4

The reshape function will do the trick here:

% Arrange the elements of val into a 1x3 array
val = reshape(val, [1 3]);

Because you are converting to a row-vector, the following syntax will also work:

val = val(:)';

Because val(:) creates a column-vector, and the transpose operator ' then transposes that column-vector into a row-vector.

Wesley Hill
  • 1,789
  • 1
  • 16
  • 27
4

The function squeeze is another option if you have a varying number of elements in the third dimension

>> squeeze(val)'
ans =
    0.7216    0.7216    0.7216

assuming that you want these numbers - the required numbers in your question don't actually match the values from the matrix val.

Adrian
  • 3,246
  • 19
  • 22
1
val = val(:)';

This should do the trick.

(:) will convert it to a column.

' will transpose it to a row

Nathan Fellman
  • 122,701
  • 101
  • 260
  • 319