Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
回复
 
主题工具 显示模式
旧 2019-12-14, 20:13   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 MATLAB中的矩阵分类

我在Mathematica中有以下代码:

nxBin = Table[{-5 sX + (i - 0.5)*step, nBin[[i]]}, {i, 1, Length[nBin]}] 而我在MATLAB中做到了:

a=zeros(length(nBin),1); nxBin=zeros(length(nBin),1); for i=1:length(nBin) anew=a*step*(i-0.5) -5*sX; b=zeros(length(nBin(i)),1); nxBin(i,:)=[anew , b] end 但是MATLAB说
???使用==> horzcat时出错
CAT参数的尺寸不一致。

==>中的错误始于52
nxBin(i,:)= [anew,b]

谁能告诉我为什么会出现此错误?另外,我可以用更少的行来做到这一点吗?



回答:

您想用步长对n×1数组nBin进行分类(直方图可能是x值)。因此,您可以简单地创建“ x向量”并将其组合。

nxBin = [ -5*sX + ((1:length(nBin))' - 0.5) * nStep, nBin(:)] 这是相同的步骤

%# make a vector with values from 1 to nBin x = 1:length(nBin); %# transpose, since it's 1-by-n and we want n-by-1 x = x'; %'# %# apply the modification to x x = -5*sX + (x-0.5)*nStep; %# catenate with nBin (the colon operator guarantees it's n-by-1 nxBin = [x, nBin(:)]; 编辑

如果要绘制此图,可以执行

plot(nxBin(:,1),nxBin(:,2),'.') 或者,如果我猜对了,那就是直方图

bar(nxBin(:,1),nxBin(:,2))

更多&回答...
poster 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 22:45


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.