由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Computation版 - 请问怎么把这个一维向量复制成三维数组
相关主题
请问怎么让m阶矩阵的每个元素减n阶矩阵的每个元素而不用for循环MATLAB积分求教
哪位前辈能指点一下怎么去掉这个for循环吗请教:求最值问题
请问怎样让一m长的向量和一mxn的矩阵相乘,仍为mxn请帮忙一个矩阵处理的问题
请问一下关于input2=input(input~=0)的用法[转载] 提个线性代数的问题,肯请热心人指教
请问怎样取三维数组某一平面的数据而得到一个两维数组一个压强计算问题
[合集] Matlab 求助:如何把一个高维矩阵中的一维赋值给一个向量谁手头上有《常用算法程序集》(C语言)?
请教matlab,将一个二维的矩阵扩展到三维的最简单的办法?[合集] 怎么产生这个矩阵?
Fortran中数组可以多大?简单Matlab问题 (转载)
相关话题的讨论汇总
话题: repmat话题: 24话题: 16话题: 30话题: 12
进入Computation版参与讨论
1 (共1页)
g******s
发帖数: 733
1
次序搞不定。
d = 8 10 4
16 20 8
24 30 12
想复制成
e(:,:,1) =
8 8 8
16 16 16
24 24 24
e(:,:,2) =
10 10 10
20 20 20
30 30 30
e(:,:,3) =
4 4 4
8 8 8
12 12 12
三维数组有什么命令可以操作次序的吗?
先谢了!
r****y
发帖数: 1437
2


most straightforward way

for i = 1:3
e(:, :, i) = reshape(repmat(d(:, i), 1, 3), 3, 3, 1);
end
I suspect "resahpe" is not necessary. You can try it.
repmat(d(:, 1), 1, 3)

【在 g******s 的大作中提到】
: 次序搞不定。
: d = 8 10 4
: 16 20 8
: 24 30 12
: 想复制成
: e(:,:,1) =
: 8 8 8
: 16 16 16
: 24 24 24
: e(:,:,2) =

g******s
发帖数: 733
3
Thank you so much. You are right, reshape is not necessary. repmat is really
good :)) I am not sure if we can remove the for loop in the codes.

【在 r****y 的大作中提到】
:
:
: most straightforward way
:
: for i = 1:3
: e(:, :, i) = reshape(repmat(d(:, i), 1, 3), 3, 3, 1);
: end
: I suspect "resahpe" is not necessary. You can try it.
: repmat(d(:, 1), 1, 3)

g******s
发帖数: 733
4
I wonder why the following codes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i = 1:3
e(:, :, i) = repmat(d(:, i), 1, 3);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
cannot be simplied as
e(:,:,1:3)=repmat(d(:,1:3),1,3);
Anyone has any ideas?
Thanks a lot!

【在 g******s 的大作中提到】
: Thank you so much. You are right, reshape is not necessary. repmat is really
: good :)) I am not sure if we can remove the for loop in the codes.

r****y
发帖数: 1437
5

You should at least read some basic books about matlab
before babbling here.

【在 g******s 的大作中提到】
: I wonder why the following codes
: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
: for i = 1:3
: e(:, :, i) = repmat(d(:, i), 1, 3);
: end
: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
: cannot be simplied as
: e(:,:,1:3)=repmat(d(:,1:3),1,3);
: Anyone has any ideas?
: Thanks a lot!

F******n
发帖数: 160
6

回答:
可以不用循环解决这个问题 - 因为MatLab是诠释性,非编译语言,优化计算速度的基本
技巧之一就是避免循环。
几个要点提示如下:
1。你得了解线性指标 (linear indexing) 的概念:查看MaLab Help --> Programming

【在 g******s 的大作中提到】
: Thank you so much. You are right, reshape is not necessary. repmat is really
: good :)) I am not sure if we can remove the for loop in the codes.

1 (共1页)
进入Computation版参与讨论
相关主题
简单Matlab问题 (转载)请问怎样取三维数组某一平面的数据而得到一个两维数组
[合集] 简单问题简单问,matlab[合集] Matlab 求助:如何把一个高维矩阵中的一维赋值给一个向量
MatLab program problem, how to use the memory wisely?请教matlab,将一个二维的矩阵扩展到三维的最简单的办法?
关于poisson方程的,特征向量Fortran中数组可以多大?
请问怎么让m阶矩阵的每个元素减n阶矩阵的每个元素而不用for循环MATLAB积分求教
哪位前辈能指点一下怎么去掉这个for循环吗请教:求最值问题
请问怎样让一m长的向量和一mxn的矩阵相乘,仍为mxn请帮忙一个矩阵处理的问题
请问一下关于input2=input(input~=0)的用法[转载] 提个线性代数的问题,肯请热心人指教
相关话题的讨论汇总
话题: repmat话题: 24话题: 16话题: 30话题: 12