MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   创建矩阵-MATLAB (https://www.labfans.com/bbs/showthread.php?t=26197)

poster 2019-12-14 20:13

创建矩阵-MATLAB
 
我来自[URL="http://en.wikipedia.org/wiki/Mathematica"]Mathematica[/URL] ,我想在[URL="http://en.wikipedia.org/wiki/MATLAB"]MATLAB中[/URL]创建它

pointers = Table[If[experiment[[i, 1]]^2 + experiment[[i, 2]]^2 > 1, 0, 1], {i, 1, npoints}]; 例如,对于npoints = 10,输出为{0,1,1,1,1,1,0,0,1,1}。

我试过了,但是错了! (我现在正在学习MATLAB,但是我从Mathematica那里学到了一些东西)

assign=experiment(i,1)^2 +experiment(i,2)^2; if assign>1 assign=0; else assign=1; end pointers=assign(1:npoints); 我也这样做,得到输出1,但这是错误的:

for i=1:npoints assign=length(experiment(i,1)^2 +experiment(i,2)^2); if assign>1 assign=0; else assign=1; end end pointers=assign

[B]回答:[/B]

在第二个示例中,您需要索引pointers ,即write

pointers(i) = assign; 而不在第二行中调用“长度”。

但是,一个更简单的解决方案是编写

pointers = (experiment(:,1).^2 + experiment(:,2).^2)


所有时间均为北京时间。现在的时间是 23:19

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