Matlab:如何更改矩阵的存储方式?从1x1x3到1x3? [英] Matlab: how do I change the way a matrix is stored? from 1x1x3 to 1x3?

查看:242
本文介绍了Matlab:如何更改矩阵的存储方式?从1x1x3到1x3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有:

val(:,:,1) =

    0.7216

val(:,:,2) =

    0.7216

val(:,:,3) =

    0.7216

但是我想要

0.7216, 0.716, 0.721.

我该怎么做?

推荐答案

reshape函数将在此处完成操作:

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(:)';

因为val(:)创建一个列向量,然后转置运算符'然后将该列向量转置为行向量.

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

这篇关于Matlab:如何更改矩阵的存储方式?从1x1x3到1x3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆