Matlab: how to change the way matrix is ​​stored? from 1x1x3 to 1x3?

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 operation can I do for this?

+3
source share
3 answers

The function reshapewill do the trick here:

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

Since you are converting to a string vector, the following syntax will also work:

val = val(:)';

Because it val(:)creates a column vector, and the transpose operator 'then transfers this column vector to the row vector.

+3
source

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

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

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

+4
val = val(:)';

.

(:) .

'

+1

Source: https://habr.com/ru/post/1786117/


All Articles