https://uk.mathworks.com/matlabcentral/answers/questions?term=tag%3A%22for+循环%22 MATLAB答案-新问题匹配标记:“for循环” 2021年10月- 07 - t19:53:35z 标签:uk.mathworks.com,2005:Question/1469151 2021-10-07T18:15:08Z 2021年10月- 07 - t19:53:35z 如何得到满足条件的第一个指标 嘿,伙计们,我用ode45解决了一个非线性方程,得到了X和T作为答案。如果abs(X(j))==0.05*(abs(X(end)) break end st=j*(10/length(T)) end我需要第一个j满足我的条件,但我不能得到它。有什么办法能解决这个问题吗?命令find()不工作。 farimah zarghami https://uk.mathworks.com/matlabcentral/profile/authors/17469784 标签:uk.mathworks.com, 2005:问题/ 1469036 2021年10月- 07 - t15:17:39z 2021年10月- 07 - t19:43:53z 多次尝试获取S(100)值 clc T=1;S(1)=3400;西格玛=0.0003;L=10;delta_t=t/L;n=linspace(0,L,L^2);mu=0;y=randn(1,L^2);M=10;对于i=1:M,对于t=1:长度(n)S(t+1)=S(t)+mu*δt*S(t)+sqrt(sigma)*sqrt(δt)*y(t)*S(t);大家好,我遇到了一个我似乎无法解决的问题。我是Matlab的初学者,正在尝试返回几个S(100)值,以便获得计算出的S(100)的平均值。但是Matlab给了我10次同样的S(100)。我想要10个不同的S(100)值。如何编写此代码?提前谢谢。 蒂姆Deutman https://uk.mathworks.com/matlabcentral/profile/authors/24158476 标签:uk.mathworks.com,2005:Question/1468566 2021-10-07T03:45:05Z 2021年10月- 07 - t07:30:27z 如何调用反向运动学代码来循环直线的每一段并将数据提取到excel? 我们已经写了一个6自由度机器人手臂的正运动学和逆运动学代码。现在我们要做一个线性运动。我们正在寻求如何编写代码的信息。我们要把每段直线的逆运动学称为。使用公式循环(x,y,z) 100次(从开始到结束),并调用inverse kinematic在每个分段进行操作。这应该给出一个100 x 6的矩阵,我们需要导出到excel。 Konard亚当斯 https://uk.mathworks.com/matlabcentral/profile/authors/19608249 标签:UK.Mathworks.com,2005:问题/ 1467571 2021 - 10 - 06 - t00:37:18z 2021年10月- 07 - t03:47:32z For循环不生成结果 我有下面的方程k应该假设1如果,假设0如果。所有其他参数都是常数。R = 2;C = 2.5;η= 2.5;Pac = 5;Tp = 76;t_delta = 1;t = 0:5/12:24;α= 1-t_delta / C (60 * R *); beta = eta*R*(9/5)+32; T0 = 86 - 14*cos(0.0035*t); Ta(1) = Tp; k(1) = 0; for j = 1:length(t) Ta(j+1) = alpha*Ta(j)+(1-alpha).*(T0(j)-k(j)*beta*Pac); if (Ta(1:j) <= Tp-0.5) k(j) = repelem(0,length(j)); Ta(j+1) = alpha*Ta(j)+(1-alpha).*(T0(j)-k(j)*beta*Pac); for m = 1:j if (Ta(1:m) >= Tp+0.5) k(m) = repelem(1,length(m)); Ta(m+1) = alpha*Ta(m)+(1-alpha).*(T0(m)-k(m)*beta*Pac); end end end end plot(t,Ta) suppose to give a pulse-like shape, similar to the shape in orange in the attached file. But I'm not getting anything close. I don't know what is wrong. Please assist. I'm very new to matlab. Shaddai. https://uk.mathworks.com/matlabcentral/profile/authors/24217157 标签:uk.mathworks.com, 2005:问题/ 1468026 2021 - 10 - 06 - t13:40:50z 2021 - 10 - 06 - t14:03:23z 截锥的面积/半径 所以我必须把6,16,和60个圆柱体放进圆锥体中,然后用它们来获得延伸率,我已经有了大部分,我只是不知道如何找到每个圆柱体的变化半径。对于面积和半径,我有:对于I=1:nr(I)=r./na(I)=pi*(r(I))^2,我知道半径是错误的,但我似乎无法确定放在那里的是什么,它还表示我刚刚丢失的raius的元素数是错误的。感谢您的帮助!更新:我把半径改为:(原来的半径是2c),圆锥体的变化半径是((R2-R2)/h(b=厚度=L./nl(I)=(1/2)*(b(I))r(I)=(r(I)=(2*c-c)/L)*L(I),但现在它说我的半径方程要么是矩阵尺寸需要一致,要么是在我放a的时候。”它说左右不同的元素数(仍然不确定半径等式是否正确), BoostedMan https://uk.mathworks.com/matlabcentral/profile/authors/19413481 标签:uk.mathworks.com,2005:Question/1467231 2021 - 10 - 05 - t14:41:25z 2021 - 10 - 06 - t12:52:07z 我想做一个x的函数,它使用循环表示(x-x(I)) 例如,如果我有一个数组x =(1 2 4)我想要输出,这是一个函数,它看起来像这样,f = @ (x) (x - 1) + (x - 1) * (x - 2) + (x - 1) * (x - 2) *(* 4)我目前想通过下面这段代码,但我仍然没有找到上面的方法使输出像% % x = [1 3 5];= 2;b = 3;For I = 1:3 c = x(I);str2func(sprintf('@(x) %.3f.*x. '))^ 2 + %。(x - %.3f)',a,b,c));A = A + 1;B = B + 1;f = fc (a, b, c)结束,例如如果我想要添加另一个数组,Y =(3 4 6)我想让输出是这个样子:(1)* (X - 1) + Y (2) * (X - 1) * (3) + Y (3) * (X - 1) * (3) * (x5) X = [1 3 5] 克拉拉维维安 https://uk.mathworks.com/matlabcentral/profile/authors/18938578 标签:uk.mathworks.com, 2005:问题/ 1466706 2021 - 10 - 04 - t23:05:07z 2021-10-06T06:37:16Z 如何创建数据表并将其导出为excel文件? 你好!我有麻烦把我的数据转换成表格,并导出为excel文件。实际上,我正在导入多个。mat矩阵文件,并将这些数据转换为每个文件的基本统计观察结果。我希望从for循环中列出所有这些值。下面是简化后的代码:datadirectory = '/Users/name/Desktop/data/';进口= dir (fullfile (datadirectory ' * .mat '));save_directory = uigetdir(' /用户/名称/桌面/数据/ ');for i = 1:length(import) Data = load(fullfile(import(i))。文件夹,进口(我). name));histogram(Data. importdata) mean = mean(Data. importdata)。importData '所有');方差=性病(数据。importData, 0, 'all'); median = median(Data.importData, 'all'); mode = halfrange(Data.importData); fileName = strrep(import(i).name,'.mat','') end What I would like to do is make a table of the filename, its respective mean, and its respective standard deviation for each loop. I understand that you would have to use the "table(...)" function, however I am unsure how to convert looped results into it. I tried the following and it doesn't work. tabData = table( filename(i), mean(:), stdev(:) ) Thank you all for your help! 鲍比 https://uk.mathwands.com/matlabcentral/profile/authors/17334986 标签:uk.mathworks.com, 2005:问题/ 1467616 2021 - 10 - 06 - t02:40:37z 2021 - 10 - 06 - t03:49:25z 用于蒙特卡罗模拟的向量化fzero函数 我运行一个蒙特卡罗模拟,例如100万个实现,在每个循环中使用fzero函数进行零搜索。对于100万次循环,代码变得非常慢。对于fzero有一个矢量化的方法吗?是否有一种快速的方法,如:x = vectorized_fzero(fun, x0)来提高效率?谢谢 旺姆 https://uk.mathworks.com/matlabcentral/profile/authors/9404411 标签:uk.mathworks.com, 2005:问题/ 1467321 2021-10-05T16:47:52Z 2021 - 10 - 05 - t17:24:04z 我如何找到样本的均值,然后找到均值? 我有一个1000*25的向量带有从1-1000000的随机整数。行表示样本,所以我有1000个样本,每个样本有25个随机整数。如何求出每一行/样本的均值,然后求出所有均值(1000个均值)的均值? 拉贝卡·穆罕默德 https://uk.mathworks.com/matlabcentral/profile/authors/14934480 标签:uk.mathworks.com,2005:Question/1467236 2021-10-05T14:48:26Z 2021-10-05T17:04:46Z 循环遍历矩阵的列并保存输出 我有一个矩阵是1000x4。每列都是不同的实验运行。我想循环遍历矩阵的每一列,并通过取每1000个值的平均值来重塑它。对于a=1:4;GTsec=平均值(重塑(水平(1:1000)、10、[])、1);%通过将超过1000个文件的平均GT值改为每秒 C.G. https://uk.mathworks.com/matlabcentral/profile/authors/13980402 标签:uk.mathworks.com,2005:Question/1467256 2021 - 10 - 05 - t15:32:01z 2021 - 10 - 05 - t15:32:01z 泰勒定理,求x =1时e^-x的近似值精度为5小数点。 你好,我是新的Matlab和需要帮助与下列问题。用泰勒定理求出x =1时e^-x的近似值,精度为5小数点。我不允许使用符号工具箱的符号。我被允许用手工计算一些零件。我需要知道(n)当我有5个小数的精度时。我一直在尝试创建一个循环,直到我得到所需的(n)并将显示那个数字。我将使用这个答案来寻找近似(我已经计算出代码)。n = 0;R = 1 /阶乘(n + 1);而R <= 0.000005 n = n+1; R = 1/factorial(n+1); end disp(n) 托夫斯托斯内斯酒店 https://uk.mathworks.com/matlabcentral/profile/authors/19248499 标签:uk.mathworks.com,2005:Question/37114 2012 - 05 - 01 - t17:00:13z 2021-10-05T14:50:08Z For循环随机暂停和重新启动 我有一个简单的代码(下面),它包含两个for循环。此代码计算信号的功率谱,并拟合对数-对数谱的斜率。m = 0 (100100);For x=1:100 For y=1:100 curr=squeeze(data(y,x,:));pcurr f = pwelch(咕咕叫 ,[],[],[], 1);页= polyfit (log10 (f), log10 (pcurr), 1);米(y, x) =页(1);结束结束代码将运行并使用了60%的CPU时间,30秒可能是马克斯,然后将暂停,看似随机的时间什么都不做,有时5 - 10分钟或更长时间才再次启动并运行了几秒。总的运行时间应该只有几分钟,但最终却花费了数小时。这不仅仅发生在这段代码中,在for循环中的其他函数也会同时使用多个处理器,比如'imfilter'。 It will also happens when I run the code as a function or in the command window. I am running Matlab r2011b on a 12-core Intel system. If anyone has any idea what I could do so that the program does not pause please let me know. 克里斯托弗 https://uk.mathworks.com/matlabcentral/profile/authors/2172863 标签:uk.mathworks.com,2005:Question/1466971 2021 - 10 - 05 - t08:14:12z 2021 - 10 - 05 - t10:03:15z 在循环中创建函数以增加输入 我需要在循环中定义一个函数来增加输入的数量。function for n=2 pA_r(3)=@(t,s1, s3) (function for n=3)其中,t,s1,…, sn变量。我不知道从哪里开始。我只需要定义它们,这样我就可以随时使用。我非常感谢你的帮助。 Md。Nurul安瓦尔 https://uk.mathworks.com/matlabcentral/profile/authors/15842530 标签:uk.mathworks.com,2005:Question/1466716 2021 - 10 - 04 - t23:20:54z 2021-10-05T03:45:23Z 制作石头、布、剪刀游戏时出错 %游戏条件user_play = input('选择R为石头,P为布,S为剪刀:');%randomness for comp_play = randi(imax,n) imax = 3;n = 1;randi(imax,n) 1 == R;2 = = P;3 = = S;end % results if user_play == R && comp_play == P || user_play == P && comp_play == S || user_play == S && comp_play == R result = 'Computer win';elseif comp_play == R && user_play == P || comp_play == S || comp_play == S && user_play == R result = '用户赢';else comp_play == R & user_play == R | comp_play == P & user_play == P | comp_play == S & user_play == S;结果=“领带”; end I wrote this code a couple days ago and I was able to successful play the game. I tried to code it so that it would rerun until x number of games was won but I couldn't get it to work. I removed that code and now when I try to input a selection for rock paper or scissors this error code pops up. Error using input Unrecognized function or variable 'R'. Error in RPS_simulator (line 3) user_play == input('chose R for rock, P for paper, S for scissors:'); I then get stuck in a loop of matlab asking me to pick R,P, or S and that error occuring. 艾丹巴勒莫 https://uk.mathworks.com/matlabcentral/profile/authors/23683056 标签:uk.mathworks.com,2005:Question/294342 2016 - 07 - 08 - t10:54:26z 2021 - 10 - 04 - t22:00:02z 如何在for循环中追加一个矩阵? 您好,我正在使用for循环来处理数据(这部分工作正常)。我需要做的是获取矩阵(A),并在每次循环后更新A以创建一个矩阵。例如,在下面的图像中,A在第一个循环上生成,在循环2期间A“增长”以包括来自循环1的数据和来自循环2的数据,依此类推<>循环1生成一个矩阵,在下一次迭代中,我需要将该循环的结果附加到该矩阵中,依此类推,直到处理完所有数据。应该注意的是,每个循环上的行数是未知的。但是,列数固定为7。如果您有任何想法,我们将不胜感激。 chels19 https://uk.mathworks.com/matlabcentral/profile/authors/5633215 标签:uk.mathworks.com, 2005:问题/ 1466499 2021-10-04T16:04:05Z 2021-10-04T16:32:05Z 使用for循环按行拆分矩阵 嗨,我有一个问题拆分一个矩阵为两个独立的矩阵使用For循环行有数字11在它和一个没有。矩阵X = [1 2 3 11 5;77 1 2 11 3;1 2 3 4 5;1 2 3 4 5;1 11 3 4 5;1 2 3 4 5]我试过以下方法…i = 1:长度(J)如果J(我:)= = 11(我:)= J其他(我,:)~ = 11 B(我:)= J端端端 约翰。史密斯 https://uk.mathworks.com/matlabcentral/profile/authors/24121232 标签:uk.mathworks.com,2005:Question/1465514 2021 - 10 - 02 - t20:19:35z 2021-10-04T15:43:05Z 使用多项式识别方法对质量弹簧阻尼参数的估计不良 因此,通过此代码,我需要获得3个参数的质量春天阻尼系统,但结果估计非常糟糕。我有f = 20sin(2pi137t)作为激励,我需要使用一种称为多项式识别的方法。所以首先,我必须创建用作多项式扩展的矩阵(1000,50),并且我必须获取激励系数和响应这些信号并使用p,然后我们可以从激发中获取参数模型回应。所以在文件1中我写了代码,在文件2中我们有二阶方程,在文件3中我们有结果(x1,x2)。关于激发和响应的%第一文件%最小平方估计(Ne = 1000 m = 50)%多项式扩展Arcostau = ACOS(-1:0.002:0.998);Arcostau = Arcostau。';p = cos(Arcostau *(1:1:50));%矩阵P [ne = 1000,m = 50]%信号激发膨胀f = 20 * sin(2 * pi * 137 *( - 1:0.002:0.998));f1 = f'; %Finding signal coefficients by least square CF = (((P')*P)^(-1))*(P')*F1; CX1 = (((P')*P)^(-1))*(P')*x1; CX2 = (((P')*P)^(-1))*(P')*x2; %Derivative calculation with a (50 by 50) matrix D=zeros(50); for row=1:50 for col=1:50 if row>col % bottom left corner if mod(row,2) ==0 && col==1 D(row,1)= row-1; end if mod(row,2)==0 && mod(col,2) ==1 && col>2 D(row,col)= (row-1)*2; end if mod(row,2) ==1 && mod(col,2) ==0 D(row,col)= (row-1)*2; end end end end %(n=3 by m=50)Least square estimation R(:,1)= CX1(:,1); R(:,2)= CX2(:,1); R(:,3)= CF(:,1); V=[((2/0.1)^2)*(((R')*R)^(-1))*(R')*(D')*CX2] % second file function dy = mck(t,y) dy = [y(2); ((-3300000/0.783)*(y(1))-(55/0.783)*y(2) +(1/0.783)*20*sin(2*pi*137*t))]; end % third file [t,y] = ode45(@mck,[0 0.121],[0; 0]); plot(t,y(:,1),'-o',t,y(:,2),'*') title('Solution of mck Equation using ODE45'); xlabel('Time t'); ylabel('Solution y'); legend('y_1','y_2') x1= y(:,1) x2=y(:,2) jana nassereddine https://uk.mathworks.com/matlabcentral/profile/authors/22314720 标签:uk.mathworks.com, 2005:问题/ 1461504 2021-09-27T10:54:37Z 2021 - 10 - 04 - t11:09:52z 如何应用一个for循环在所有表与公共索引 你好,我有一个结构,其中多个表被组合。我可以通过索引来访问它们。我想在所有具有公共索引的表中应用一个for循环。我有更多像HYT的结构,我想格式化索引中包含FLS的所有表和包含ULS的所有表。所以* .FLS。和* .ULS。HYT。将是不同的每个结构,但FLS和ULS将始终存在,以及Float和LR在每个FLS和ULS内。所以工作区中的变量看起来像这样:HYT ABC DEF,然后在每个变量中我们都有浮动和LR的FLS和ULS。我希望将相同的操作和计算应用到FLS内的所有表,以及工作空间中所有变量的所有ULS内的所有表。 Thank you very much in advance. Usune艾利赞多 https://uk.mathworks.com/matlabcentral/profile/authors/19419201 标签:uk.mathworks.com,2005:Question/1465874 2021 - 10 - 03 - t19:50:09z 2021-10-03T23:29:14Z 四种不同的输出结果总是以相同的“答案”结束,而我不相信它们应该是这样的。 我试着画出一个粒子100步的路径,运行100次,随机选择向上,向下,向左或向右。我想找到距离的平方根(步数的平方根)和最终的位置。距离,距离,平方根,和平均距离都是相同的,我不知道为什么。任何帮助都将不胜感激。作业问题:写一个二维随机行走的模拟,粒子站在一个交叉点上,选择向左、向右、向上或向下。最终的平均位置是零,距离的平方根是步数的平方根。尝试100步和1000步,并运行模拟100次。确保最终的位置和均方根距离是你所期望的。在每次运行的模拟中显示粒子的路径图。Pos =[0 0] distance =[] coinx= 0 coiny = 0 figure for j=1:1 for i=1:100 coinx=rand; coiny=rand; if coinx>0.5 pos(1)=pos(1)+1; else pos(1)=pos(1)-1; end if coiny>0.5 pos(2)=pos(2)+1; else pos(2)=pos(2)-1; end plot(pos(1),pos(2),'ro'); hold on end distance=sqrt(pos(1)^2+sqrt(pos(2)^2)) distances=[distances distance] hold on pos=[0 0]; end rootmeansquared=rms(distances) meandist=mean(distances) %This is the final position Thank you. 克里斯汀·奥尔德里奇 https://uk.mathworks.com/matlabcentral/profile/authors/23114133 标签:uk.mathworks.com, 2005:问题/ 1465549 2021 - 10 - 02 - t21:27:58z 2021-10-03T19:33:53Z Matlab:我如何创建一个For循环来计算数组中的正数和负数的数量? 嗨,我已经生成了一个随机的整数1x20数组,由-40到40之间的数字组成,如下所示:x =兰迪(40[-40]1 20)下一步是使用一个for循环检查数组中的每个数字和计算的积极的和消极的数字,然后生成一个新的数组' d '每个位置的x是正将一个1和- 1谢谢 约翰。史密斯 https://uk.mathworks.com/matlabcentral/profile/authors/24121232 标签:uk.mathworks.com, 2005:问题/ 484531 2019-10-10T06:18:31Z 2021-10-03T18:16:45Z 如何对电动汽车及其充放电进行建模 想要为电动汽车(30kW电池容量)建模,并使用3kW/5kW/10kW充电器按1C/2C/3C费率充电,耗电量为150Wh/km。如何在simulink中对其建模,从变压器对其充电,并在一定时间段内放电后再充电。首先需要模拟一辆电动汽车,然后我将通过多辆不同电池容量的电动汽车及其充放电特性。还请提供任何用于模拟研究万博1manbetx的参考,谢谢 穆克什·库马尔 https://uk.mathworks.com/matlabcentral/profile/authors/9934578 标签:uk.mathworks.com, 2005:问题/ 1465844 2021 - 10 - 03 - t17:31:32z 2021 - 10 - 03 - t18:15:17z 错误:如何存储for循环中的值? 我在文件交换上使用getDataTips来提取数据提示信息。我编写了一个for循环,以便只提取索引值,因为getDataTips提取[X,Y]、index和[R,G,B],其中索引值是466.833、405.573,等等。(见附件图片)。我想总结11个数据提示。我试图将for循环的所有值存储到一个数组中使用如下语句:1 a1 = 0(11日);For I = 1:s x(I +1) = content{1,1}{I,1}{2};a1(11,我)= x (i + 1);x(i+1) = content{1,1}{i,1}{2}. x(i+1) = content{1,1}{1,1}当我做,因为我= 1:s内容{1},{我1}{2}结束它输出:ans =“指数466.833”ans =“指数405.573”我知道我没有写正确我的for循环编码时,试图把它放到一个数组,但是我不确定什么是错误的,因为这是我第一次写一个for循环。 So any help on this would be much appreciated! 加布里埃李 https://uk.mathworks.com/matlabcentral/profile/authors/19665315 标签:uk.mathworks.com,2005:Question/383291 2018 - 02年- 18 - t00:00:17z 2021-10-03T14:40:22Z 如何使用for循环和if语句来查找二维数组中的数字并替换它们? 我需要把A=[1 2 4;3 2 1;2 4 5;-2 -1 10],使用for循环和if语句。下面是我的代码,但它什么都做不了。请告诉我哪里做错了。for i=A if i<0 A(i)=0;结束结束 BCLAcowgirl # 1 https://uk.mathworks.com/matlabcentral/profile/authors/5591116 标签:uk.mathworks.com,2005:Question/449778 2019-03-13T07:44:00Z 2021-10-03T13:33:09Z 将小时数据转换为每日数据 大家好,我每小时都有一些数据,我想将它们转换为每天(每天均为24行的平均值)。我已经创建了以下循环,但我缺少一个值。对于特定时期,我应该收到1461行(天),但我收到1460.有人可以帮助我吗?t = 1;k = 1;步骤= 24;对于i - 步骤:步骤:长度(x)-step;如果我>步;a = x(i-step:i);否则a = x(k:i); end; AverageDailyData(k,t) = mean(a)q k=k+1; end 卡斯库拉斯 https://uk.mathworks.com/matlabcentral/profile/authors/15024590 标签:uk.mathworks.com,2005:Question/1465294 2021-10-02T11:13:37Z 2021-10-03T06:07:12Z 如何将代码中的嵌套循环矢量化以提高性能? 您好,我不知道如何对嵌套循环集进行矢量化。如何通过矢量化提高代码的速度?此外,是否有比ismember更快的方法检查数组中当前是否存在值?ismember是该计划的一个重要瓶颈。任何其他值得注意的优化或建议也将不胜感激。脚本在定义的限制内计算基本限制比率。示例代码中定义的限制只需几秒钟即可运行。随着素数限制的增加,计算所需的时间将以指数形式增加,因为它必须将当前素数乘以之前发送到数组的每个分子和分母。这是代码:%define limits primeLimit=11;integerLimit=intmax('int32');八平均值=2;printEachLimit=0;sortType=“ƒ比率”;%设置比率计数器阵列计数器=2;%初始化数组primeOptionArray=primes(primeLimit);primeLimitArray=[2];numeArray=[1];denoArray=[1];fRatioArray=[1];centsArray=[0];tenneyHeightArray=[0];%循环通过i=1的每个素数:长度(素数选项阵列)tic;currentPrime=primeOptionArray(i);%获取当前prime disp(currentPrime+“-极限计算…”);progressArrayLength=arrayCounter;%基于以前的数组大小设置长度,用于通过数组中的所有比率计算循环的进度百分比,乘以ii=1的当前素数:arrayCounter nume=numeArray(ii);%获取分子deno=denoArray(ii);%当nume<=整数限制nume=nume*当前素数;%时,在限制范围内获取分母%乘以素数将分母乘以2,直到比率在规定的倍频程内,而nume/deno>octaveRatio deno=deno*2;end fRatio=nume/deno;%频率比,如果fRatio>1&&fRatio<=octaveRatio%,在再次检查极限之前,将比率降低为最简单的形式比率CD=gcd(nume,deno);简化nume=nume/比率CD;reducedeno=deno/ratioGCD;%检查比率是否在限制范围内,如果已找到,则如果已还原Nume<=整数限制ismember(fRatio,fRatioArray)==0 primeLimitArray(arrayCounter)=currentPrime,则推送到数组;numerary(数组计数器)=减少的nume;denoArray(arrayCounter)=简化的Deno;fRatioArray(阵列计数器)=fRatio;中心线(阵列计数器)=1200*log2(弗拉蒂奥);tenneyHeightArray(arrayCounter)=log2(简化的Nume*简化的Deno);nume=还原nume;deno=还原的deno;arrayCounter=arrayCounter+1;%自从找到比率并将其添加到数组结束%后,向上计数1执行反向计算nume=numeArray(ii);%获取分子deno=denoArray(ii);%当nume<=整数限制nume=nume*2;%时,在限制范围内获取分母%乘以分子2;%将分母乘以素数,直到比率在规定的倍频程内,而nume/deno>octaveRatio deno=deno*currentPrime;end fRatio=nume/deno;%频率比,如果fRatio>1&&fRatio<=octaveRatio%,在再次检查极限之前,将比率降低为最简单的形式比率CD=gcd(nume,deno);简化nume=nume/比率CD;reducedeno=deno/ratioGCD;%检查比率是否在限制范围内,如果已找到,则如果已还原Nume<=整数限制ismember(fRatio,fRatioArray)==0 primeLimitArray(arrayCounter)=currentPrime,则推送到数组;numerary(数组计数器)=减少的nume;denoArray(arrayCounter)=简化的Deno;fRatioArray(阵列计数器)=fRatio;中心线(阵列计数器)=1200*log2(弗拉蒂奥);tenneyHeightArray(arrayCounter)=log2(简化的Nume*简化的Deno);nume=还原nume;deno=还原的deno;arrayCounter=arrayCounter+1;%自找到比率并将其添加到阵列结束%update progress后,向上计数1。。。如果currentPrime>2,如果(ii==四舍五入(progressArrayLength*0.25))elapsedTime=toc;显示(“25%”+elapsedTime+s”);elseif(ii==四舍五入(progressArrayLength*0.5))elapsedTime=toc;显示(“50%”+elapsedTime+s”);elseif(ii==四舍五入(progressArrayLength*0.75))elapsedTime=toc;显示(“75%”+elapsedTime+s”);elseif(ii==四舍五入(progressArrayLength))elapsedTime=toc;显示(“100%”+elapsedTime+s”);结束%保存每个基本限制的文件,如果currentPrime>2&&printEachLimit==1 elapsedTime=toc,则包含所有以前的数据;disp(“写入CSV文件…”);dataMatrix=[numeArray;denoArray;fRatioArray;centsArray;tenneyHeightArray;primeLimitArray];%创建矩阵dataMatrix=dataMatrix.;%如果sortType==“ƒRatio”dataMatrix=sortrows(dataMatrix,3),则转置行和列;elseif sortType==“Tenney Height”数据矩阵=sortrows(数据矩阵,5);end dataMatrix=array2table(dataMatrix);变量名称(1:6)={‘分子’、‘分母’、‘比值’、‘美分’、‘Tenney高度’、‘质数极限’;fileTitle=[num2str(长度(primeLimitArray)),'rations',num2str(currentPrime),'-limit',num2str(整数限制),'-int-limit',num2str(round(elapsedTime)),'s.csv'];可写(数据矩阵、文件标题);结束%如果printEachLimit==0 elapsedTime=toc,则保存一个包含找到的所有数据的文件;disp(“写入CSV文件…”);dataMatrix=[numeArray;denoArray;fRatioArray;centsArray;tenneyHeightArray;primeLimitArray]; %create matrix dataMatrix = dataMatrix.'; %transpose rows & columns if sortType == "ƒ Ratio" dataMatrix = sortrows(dataMatrix,3); elseif sortType == "Tenney Height" dataMatrix = sortrows(dataMatrix,5); end dataMatrix = array2table(dataMatrix); dataMatrix.Properties.VariableNames(1:6) = {'Numerator','Denominator','ƒ Ratio','Cents','Tenney Height','Prime Limit'}; fileTitle = [num2str(length(primeLimitArray)),' Ratios ',num2str(primeOptionArray(end)),'-limit ',num2str(integerLimit),'-int-limit ',num2str(round(elapsedTime)),'s.csv']; writetable(dataMatrix,fileTitle); end elapsedTime = toc; disp("Complete. "+length(primeLimitArray)+" Ratios Found. "+elapsedTime+"s"); Note: "gcdFast" reduces the runtime by half, but has been changed to the default gcd for this example to remove dependencies. Tianhuojian https://uk.mathworks.com/matlabcentral/profile/authors/24101632 标签:uk.mathworks.com,2005:Question/1465574 2021-10-02T23:09:59Z 2021-10-03T00:07:48Z 如何在for循环中引用矩阵值? 对于下面的代码,我尝试让我的For循环获取ZL, D和Q的输入,每个循环的每一行,如下面的代码所定义。然而,我不能引用每个变量,因为我会使用语法假设:值从1开始,去新泽西(1)为每个值并完成内心的for循环,然后for循环2,从1开始,去新泽西(2)和完整的内部循环的每个值等,直到没有更多的循环和新泽西的值。最终结果:请运行代码,您将看到我尝试采用的方法。我的最终目标是能够为(loop,line)的任何组合单独引用每个变量。我知道这是一个简单的命令,但我不确定。谢谢你!代码:clc;clearvars;NL = input('请输入系统中循环的数量'); fprintf('\n'); for loop1 = 1:NL fprintf('Enter the number of lines in loop %g: ',loop1); NJ(loop1)=input(''); fprintf('\n'); end shared = input('How many lines are shared by two loops?: '); fprintf('\n'); nodes = input('Please enter the number of nodes in the system: '); fprintf('\n'); asum = ((sum(NJ) - shared) - nodes + 1); X = [num2str(asum),' assumption(s) for flow rate must be made in order to solve for the flow rate distribution.']; disp(X) fprintf('\n'); for loop = 1:NL for line = 1:NJ(1:end) fprintf('Enter the length (in feet) of line %g in loop %g in feet: ',line, loop); ZL(loop, line) = input(''); fprintf('\n'); fprintf('Enter the diameter (in feet)of line %g in loop %g in feet: ',line, loop); D(loop, line) = input(''); fprintf('\n'); fprintf('Enter the flow rate of line %g in loop %g in ft^3/s(if unknown make assumption now): ',line, loop); Q(loop, line) = input(''); fprintf('\n'); end end 卢克·波拉克 https://uk.mathworks.com/matlabcentral/profile/authors/18568700 标签:uk.mathworks.com,2005:Question/1465454 2021-10-02T18:38:27Z 2021 - 10 - 02 - t19:32:31z 我需要找到一个物体“走”到离原点10“步”的平均步数? 我有一个代码绘制了100个对象的路径,并在远离原点的步骤时停止它们。我需要找到它们需要逃离原点所需的平均步骤数。下面的代码:n = 100 pos = 0 stepcount = 0图k = 1:n pos = 0;位置= [];ABS(POS)<10硬币=兰特;stepcount = stepcount + 1;如果硬币> = 0.5 POS = POS-1;否则POS = POS + 1;结束位置= [位置POS];结束绘图(位置)保持最终FinalStepmean =均值(stepCount)我的最终的eptepmean应该是appx 100,它是使用此代码的,但我只有1个路径绘制而不是我需要的100。 If I remove stepcount=stepcount+1, it shows the 100 paths but obviously my mean ends up being 0, or if I move it to outside the while loop it ends up being over 10,000. I'm not sure where I'm going wrong here. Thanks in advance! Homework problem: We used a while loop to create a random walk simulation that ran until it reached 100 steps. Use a while loop to create a simulation that runs until the particle is 10 units away from the origin. We saw in class that the root mean square distance is the square root of the number of steps; therefore, if your simulation is working correctly, it should run for an average of 100 steps before reaching a distance of 10 units (but some runs will run for more or fewer steps!)- be sure to measure the mean number of steps. Your code should also make a plot of the particle’s path for each run of the simulation. Somewhere on this plot (title or x-axis is fine), indicate the average number of steps. 克里斯汀·奥尔德里奇 https://uk.mathworks.com/matlabcentral/profile/authors/23114133 标签:uk.mathworks.com, 2005:问题/ 1465449 2021-10-02T18:30:59Z 2021-10-02T19:00:00Z 我如何实现这个循环计算在直接矩阵或矢量计算? 我有一个矩阵a (n+1)*3。我要做一个计算。For循环的实现如下所示。R = 0.0;j = 1:1: n R = R + ((j + 1, 1)——(j, 1)) ^ 2 + ((j + 1, 2)——(j, 2)) ^ 2 + ((j + 1, 3)——(j, 3)) ^ 2;我如何使用矩阵或向量符号实现上述计算。我需要这个使优化代码运行更快。谢谢你! 萨蒂亚吉特戈什 https://uk.mathworks.com/matlabcentral/profile/authors/18650349 标签:uk.mathworks.com, 2005:问题/ 1465059 2021 - 10 - 01 - t21:09:58z 2021 - 10 - 01 - t22:12:59z 在不使用for循环的情况下,如何将大于9的矩阵元素替换为值9? 我正在研究一个优化问题。为了让它运行得更快,我需要在定义的函数中使用矩阵进行计算,而不是使用foor循环。在这种情况下,我有一个问题,行矩阵元素需要替换为9,如果它大于9。这可以使用一些矩阵表示法来完成,或者我必须使用for循环。谢谢 萨蒂亚吉特戈什 https://uk.mathworks.com/matlabcentral/profile/authors/18650349 标签:uk.mathworks.com,2005:Question/1464594 2021-10-01T10:13:18Z 2021 - 10 - 01 - t19:10:01z 我如何添加一个for循环if命令到一个预先存在的表 您好,我是Matlab的新手,有学生版本,没有附加组件,我需要在表中包含一个循环if命令,下面是我的代码shop1=[4,5,3,6,0,5,5,6,4,5];shop2=[5,3,1,1,3,5,3,6,3,3];day=1:10;profit1=3*shop1;profit2=4*shop2;disp('day shop1 profit1')')'disp('day shop1')disp('day profit2'))disp([day',shop2',profit2'])disp([profit1',profit2'])disp([profit1',profit2'])d=1:10;%如果profit1(d)>profit2(d)disp('Shop1是领先的')或者profit2(d)>profit2(d)disp('shop2是领先的'),我需要将这些结果作为profit1 profit2表的第三列插入销售结束=查找(shop1==shop2);disp(‘销售相同的天数’)disp(‘销售相同的天数’)disp(’)disp(‘销售相同的天数’)disp(长度’)非常感谢您的帮助谢谢 特雷西 https://uk.mathworks.com/matlabcentral/profile/authors/23733929 标签:uk.mathworks.com, 2005:问题/ 1464989 2021 - 10 - 01 - t18:21:08z 2021 - 10 - 01 - t18:39:11z 如何在不使用for循环的情况下将多个变量赋值给数组中的类的变量。 我发现很难提出我的问题。这是我的问题:classdef myClassA 卡尔·弗雷德里克·Wirgenes https://uk.mathworks.com/matlabcentral/profile/authors/13395756 标签:uk.mathworks.com, 2005:问题/ 807792 2021 - 04 - 20 - t15:23:54z 2021 - 10 - 01 - t15:05:15z 在for循环中继续下一次迭代,同时保存数据 我有一个for循环,在每次迭代中它产生大约1Gb的数据。由于它需要一些时间来保存数据到硬盘驱动器,我想使用一个不同的worker来保存数据,并让for循环继续到下一个迭代,同时在原始worker上。有办法做到吗?谢谢你!编辑:每次迭代保存数据之前的计算时间比保存到磁盘的时间长,因此在下一次迭代中,当前worker在其他worker完成当前迭代的保存之前不会到达save命令。 Weixin王 https://uk.mathworks.com/matlabcentral/profile/authors/8655303 标签:uk.mathworks.com, 2005:问题/ 1464564 2021-10-01T09:03:28Z 2021 - 10 - 01 - t09:15:38z 将输出转换为行向量 我需要将b的所有输出转换为行向量大小[1 5],因此b=[4,1,0,1,4]对于a=-2:2 b=a.^2结束输出是b=4 b=1 b=0 b=1 b=4我尝试了a=-2:2 b(a)=a.^2结束,数组索引必须是正整数或逻辑值。于是我试着用a=-2:2b(1:a)=a.^2结束,但我没有得到我想要的。 Gustavo Avina https://uk.mathworks.com/matlabcentral/profile/authors/20835723 标签:uk.mathworks.com, 2005:问题/ 1464344 2021-09-30T23:16:55Z 2021-09-30T23:53:57Z 循环索引变量范围 我在用MATLAB写代码,结果输出出了问题。我从一开始就花了很多时间检查每一个东西,因为MATLAB没有指出脚本中的任何错误。在花了30分钟后,我发现我正在使用一个循环索引变量,这是另一个循环。像第二个循环我错误地使用,而不是k所以不要给任何错误或警告迹象只是使用我的最后一个值= 3是不是应该给错误或警告该变量没有定义在全球循环2或局部循环1中定义。For I = 1:3 disp(I) end For k = 1:2 disp(I) end 穆罕默德·乌斯曼 https://uk.mathworks.com/matlabcentral/profile/authors/20832568 标签:uk.mathworks.com,2005:Question/1464319 2021-09-30T21:30:38Z 2021-09-30T21:45:40Z lopp中输入和输出的无限数量 R=150;C=20.*10^-3;t=[0;1;2;3;4;5];对于Vin=input(“输入V:”)Vout=Vin.*(1-(exp(1)。^(-t./(R.*C)))结束这是我编写的代码。它将只接收一个Vin输入,因此仅显示一个Vout输出。我想改变这个循环,这样就可以输入无限多的输入,从而产生无限多的输出,并且还可以为每个输入值存储输出Vout。现在,如果我再次运行该程序,第一个Vin和Vout值将丢失。 Zarmeen汗 https://uk.mathworks.com/matlabcentral/profile/authors/23912097 标签:uk.mathworks.com, 2005:问题/ 1463769 2021-09-30T05:53:54Z 2021-09-30T19:41:35Z 如何通过MATLAB脚本显示工作区变量文件名? 哪一行代码将显示正在使用的工作区变量文件名(因此在本例中它将是一个.mat文件)?我的目标是使文件名与其各自绘制的直方图相匹配。所述代码将是现有脚本的一部分,该脚本正在分析for循环中的多个.mat文件。感谢所有回应和帮助的人! 鲍比 https://uk.mathwands.com/matlabcentral/profile/authors/17334986 标签:uk.mathworks.com, 2005:问题/ 1463239 2021 - 09 - 29 - t13:15:18z 2021 - 09 - 30 - t13:09:37z 试图得到一个列中不同变量的列表 我正在尝试创建一个数组,它显示不同类型的变量,我有一个列标签'五'在一个表我有。变量是机场名称,所以我只需要看看我从多少个不同的机场收集不同的数据。这里添加的表格显示了我正在使用的内容。目前的代码是这样的:clc clear all raw_data = readtable('n10013911.csv');i = 1;缩略词= 0 (10,1);for loop = acronym for index = raw_data(:,'Five') ii=1 if index == acronym(ii) ii=ii+1;else acronym(i,1) = raw_data(ii,'Five');I = I + 1;2 = 2 + 1; end end end I'm not the best at for loops and if statements, but this one just doesnt seem to want to work 艾丽斯·布伦顿 https://uk.mathworks.com/matlabcentral/profile/authors/10771001 标签:UK.Mathworks.com,2005:问题/ 364960 2017-11-03T16:34:57Z 2021-09-30T10:30:18Z 在循环中使用writetable将每次迭代另存为新行 我正在尝试在循环中使用可编织,以便每次迭代都在新行上打印。由于数据只有一行,我想要像A1,A2,A3一样的东西......但似乎这似乎无法完成,因为'A1'是一个字符串。这就是我所拥有的:对于w = 1:n%每个文件夹都有一个不同数量的文件由n t(1:1,:)标注(t,filename,'张',1,'范围','a(w)')%这需要是'a1'来分配表的位置,但有没有办法使用(索引)?结束感谢一堆 埃里克·詹金斯 https://uk.mathworks.com/matlabcentral/profile/authors/8759298 标签:uk.mathworks.com, 2005:问题/ 1462319 2021-09-28T10:24:41Z 2021-09-30T07:29:17Z 如何为每个循环检索不同数组输出的最后一个条目? 我有一个函数返回不同长度的数组的输出。如何在每个循环步骤中检索每个数组的最后一项?假设对于a=1:1:10的每个循环项,输出数组的长度不同,xinit=0:0.1:1;solinit = (xinit, [1 1 0]);bvp4c =索尔(@ode @bcs solinit);%%函数ode包含a的值,对于每个a输出有不同的长度v=sol.y(1,11);流(% g \ n、v);现在sol。y(1,11)会给出解y的最后一项,但是随着a的变化,数组的长度也会改变。那么我如何为每个'a'打印最后的输出呢? 谭雅·夏尔马 https://uk.mathworks.com/matlabcentral/profile/authors/16417925 标签:uk.mathworks.com,2005:Question/1461014 2021-09-26T14:02:39Z 2021 - 09 - 30 - t05:07:43z 结合LineStyleOrder和ColorOrder 大家好,我有一个数据集,我想通过在同一时间循环一组特定的颜色和线型来绘制它。我的问题是,当颜色循环时,线条样式不会。有人知道我做错了什么吗?y2=randi([10 50],14,12);集合(gcf,'DefaultAxeColorder',[0,0,1;..0,0.7,0.3;..0.5,0,1;..0,0,0;..0.6,0.6,0.6;..0,0,0;..0,0.75,0.75;..0.9,0,0.1;..1,0.6,0;..0.3,0.3],…'DefaultAxesLineStyleOrder',{-o','-,'-,'-,'-,'-,'-,'-,'-,'-,'-,'-,'-,'-,'-,'-,'-x'-,'-,'-,'-,'-,'-,'-,'-,'-,'-,'-),'-,'-,'-,'-),';ax=gca;对于i=1:size(y2,2)图(x,y2(:,2:end));ax.LineStyleOrderIndex=ax.ColorOrderIndex;终止 Eyk. https://uk.mathworks.com/matlabcentral/profile/authors/23990542 标签:uk.mathworks.com, 2005:问题/ 1459614 2021-09-23T21:47:03Z 2021-09-29T23:51:45Z 在矩阵中加倍输出? Matlab新手,请原谅。我正在尝试创建一个矩阵,mom,它使用每个文件的第4列中的数据进行更新:myDir=uigetdir;my_mom_Files=dir(fullfile(myDir,'MRFbeam-mom-*.txt');mom=[];for k=1:length(my_mom_Files)baseFileName=my_mom_Files(k)。name;fullFileName=fullfile(myDir,baseFileName);%fprinf(1,'正在读取%s\n',fullFileName);mom_data=load(fullFileName);mom_col=mom_data(:,4);mom=[mom;{mom_col}];结束输出如下:{6181×1 double}{7849×1 double}{3107×1 double}{3107×1 double}{2999×1 double}{2999×1 double}{2000×1 double}{{6181×1 double}{4425×1 double}{2499×1 double}{2499×1 double}{11293×1 double}{29980×1 double}{29980×1 double}{4825×1 double}{1123×1 double}{2221×1 double}{2221×1 double}{当我尝试cell2mat时,矩阵的大小从28 x 1变为数千。最终,我希望打印每个文件的值并将其存储在矩阵中。我的最终目标是绘制这些值。TYIA 诺古杜塞 https://uk.mathworks.com/matlabcentral/profile/authors/15011106 标签:uk.mathworks.com, 2005:问题/ 1462859 2021-09-29T04:33:38Z 2021 - 09 - 29 - t22:47:29z 我如何为位于MATLAB之外的一个文件夹中的多个.mat文件绘制直方图? 我是新使用MATLAB分析和可视化许多单个文件的数据。情况是这样的:我有多个(20+,但当然可以扩展到50-60+范围).mat文件,它们通常(但不总是)以1024x1024矩阵的形式存在。这些.mat文件被自动放置在MATLAB外部的一个文件夹中(文件夹的位置被指定为一个单独的脚本中的保存文件路径)。每个代码共享一个共同的命名标签(即。可用于识别目标.mat文件的标识文本)。我希望能够生成一个可重用的代码,它可以获取该文件路径中所有选中的.mat文件,并同时为每个.mat生成一个直方图。矩阵的值可以不同,所以我不想对坐标轴或行/列施加任何约束。下面的代码指定了我电脑上的文件路径。mat文件位于目录= '/Users/NAME/Desktop/ selectedmatrix/ ';realdata = dir(目录);%MATLAB版本:9.7.0.1261785 (R2019b)更新3我不确定从这里去哪里,或即使我上面列出的代码甚至需要我打算。 I do have some suspiscion that a for loop would play a role in the code that would be generated, but I do not know how to structure it. I have scoured MathWorks for previously asked questions in a similiar predicament to mine, however my efforts were fruitless. I am very much open to any ideas or codes that the community can provide! Thank you so much everyone! TLDR; I would like to take multiple .mat files in an outside folder and run them through MATLAB code to produce a histogram per file 鲍比 https://uk.mathwands.com/matlabcentral/profile/authors/17334986 标签:uk.mathworks.com, 2005:问题/ 1463299 2021 - 09 - 29 - t14:24:00z 2021 - 09 - 29 - t18:19:56z 如何将单元格第k列的大小指定给第k+1列? 大家好,我需要将单元格第k列的大小指定给for循环中的第k+1列。此表单似乎不起作用,因为索引超过了数组元素数(1)。sbc{k}=大小(周期{k+1}); 弗拉维亚勒拉 https://uk.mathworks.com/matlabcentral/profile/authors/15642607 标签:uk.mathworks.com, 2005:问题/ 1463414 2021 - 09 - 29 - t16:21:15z 2021 - 09 - 29 - t16:30:55z 将答案循环成向量 请参阅下面的代码。我想运行一个for循环,它将使用从linspace得到的x值在等式y中循环20次。然后我想把循环中y的每个值保存到一个向量中。谁能帮帮我吗。希望这是有道理的。clc,全部清除,全部关闭b=10;d=10;E=207E9;p=-8000;I=(b*d^3)/12;l=227;x=linspace(1226,20);对于i=1:长度(x)y=(p*x^2*(3*l-x)/(6*E*i))结束 米切麦克唐纳 https://uk.mathworks.com/matlabcentral/profile/authors/14099994 标签:uk.mathworks.com,2005:Question/1463339 2021 - 09 - 29 - t15:36:56z 2021-09-29T15:52:38Z For循环中包含零 我有两个1 × 48的矩阵我试着把它们画在一起。Y向量在数据的开始和结束处都是零,当与X相对时,我得到了一个抛物线图,忽略了偏离轨道的零值。我想消除零他们各自的X和Y值使用搜索的数组的长度和任何非零元素存储在Y在一个新的向量并将各自的X值存储在一个新的向量来画。我已经创建了下面的for循环它消除了0和Y的结尾但不排除开始的1。我做错了什么吗?这是密码,不过不是48而是20个数字。正如你所看到的,在y中只有10个非零,但是当我运行代码时,newY给了我一个1x15而不是1x10,因为它包含了前5个零。X =[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20];Y =[0 0 0 0 1 2 3 4 5 5 4 3 2 1 0 0 0 0];for i=1:20 if y(i)>0 newY(i)=y(i); newX(i)=x(i); end end 罗伯特·穆尼奥斯 https://uk.mathworks.com/matlabcentral/profile/authors/19571050 标签:uk.mathworks.com,2005:Question/1462414 2021-09-28813:30:01Z 2021-09-29T14:38:41Z 如何对0和1列使用逻辑索引 你好!我仍在学习matlab的基础知识,我与逻辑索引有困难。每个excel表格的列数相同,但行数不同。我想要取列“data(:,end-6)”,它有一个列为0和1,取所有的行有数字1,并创建一个新的数组,做更多的数学计算,只使用该列中数字1的行。任何帮助都将不胜感激。谢谢你! iceskating911 https://uk.mathworks.com/matlabcentral/profile/authors/14618324 标签:uk.mathworks.com,2005:Question/1462779 2021-09-29T01:19:19Z 2021 - 09 - 29 - t14:28:01z 如何将双循环结果逐列存储到矩阵中? 我有一个矩阵循环;我要做的是找出满足条件的点并将它们上下存储到数组中;当cycle1是一列时,它是可行的;但是当cycle1增加到2列时,双循环就不起作用了。上下的大小是不确定的;我估计它们的尺寸是100*12;现在代码没有错误,但是给出了错误的结果。请给我一些关于这个代码的建议。cycle1 = [butterworth_filter1, butterworth_filter2];[m,n] = size(cycle1) up = 0 (100,12); down = zeros(100,12); k=1; for j = 1:n for i = 1:m if i == m break elseif cycle1(i,j) < 1.5e-5 && cycle1(i+1,j) > 1.5e-5 up(k,:) = i + 1; k = k+1; elseif cycle1(i,j) > 1.5e-5 && cycle1(i+1,j) < 1.5e-5 down(k,:) = i; k = k+1; end end end 雷雳 https://uk.mathworks.com/matlabcentral/profile/authors/22001023 标签:uk.mathworks.com,2005:Question/1463169 2021-09-29T11:38:54Z 2021-09-29T13:04:06Z 如何将日志刻度(即10 ^ -1)添加为此极字绘图的x轴标签? 大家好!我想知道是否有可能在我所附的代码所创建的图形的x轴上包含一个对数尺度!我尝试了semilogx函数,但返回了一个错误消息。任何帮助都将不胜感激!我的代码如下,附件是附带相关数据的Mat-file。清除所有;%清除所有数据,避免混淆关闭所有;%% load('matlab both gamma - Copy');%加载数据文件。图(); % Open a new graph leg={}; % Declare legend as leg for i=1:length(data) % Loop over all data polarplot(data(i).beta*pi/180,log(data(i).Ns)); % Polar plot data with angle =beta (in radian), and radius =Ns. hold on; % Keep the data. Next plot will plot on the same graph leg = [leg, data(i).name]; % Add the name of data to leg end thetalim([0 90]); % Set theta limit to 90 degrees thetaticks(0:5:90); % Set theta ticks to 10 degrees rticks(0:0.2:90); % Set Ns ticks to 2 (max 24 for this data) legend(leg); % Set legend as leg rticklabels({'','','','','','Ns','','','','','',''}); % Set label for radius 托马斯·斯托克斯 https://uk.mathworks.com/matlabcentral/profile/authors/23887388 标签:uk.mathworks.com,2005:Question/1463184 2021 - 09 - 29 - t12:07:46z 2021-09-29T12:19:55Z 没有for循环的数组的代价矩阵。 嗨,我想创建一个矩阵包含数组中每个点之间的绝对值。我的数组叫做domain,它的长度是grid_number。我已经在下面的代码中这样做了,但是我使用了for循环。当grid_number较大时,运行时间较长。有没有简单的方法来做这件事?For i=1:grid_number For j=1:grid_number cost(i,j)=abs(domain(i)-domain(j)) end end结束 丹尼尔·亚当斯 https://uk.mathworks.com/matlabcentral/profile/authors/13612564 标签:uk.mathworks.com, 2005:问题/ 1463009 2021 - 09 - 29 - t07:54:12z 2021-09-29T09:19:41Z 如何从for循环中收集输出矩阵 当我从for循环clc得到2个矩阵或n个矩阵时,n=2;对于i=1:na=randi(5,3,3)如何结束A1+A2(A1,A2,其中i=1,2) 丁字裤 https://uk.mathworks.com/matlabcentral/profile/authors/24118769