matlab循环存储不同变量,matlab - 有没有办法将矩阵的值存储在一个单独的变量中,在while循环的每个循环中,以便我在一次结束时获得Matrix的所有值 - SO中文参考 - www.so...

有没有办法将矩阵的值存储在一个单独的变量中,在while循环的每个循环中,以便我在一次结束时获得Matrix的所有值

问题描述 投票:0回答:1

我想在一个单独的变量中保存矩阵(矩阵是矩阵的名称)值,以便我最后收集所有矩阵,然后一次打印所有矩阵。我的当前代码在每个循环中打印值,而我想在最后一个循环中获取所有矩阵值。

syms num T1 T2 T3 T4 T3 T6 T7 T8 T9 T10 T5

%Getting data for Robot%

prompt = 'Enter the number of joints in your robot';

X = input(prompt);

num = 0;

while(num

matrix_number = ['t ',num2str(num),'_', num2str(num+1)];

link_twist = ['Enter the value of twist(alpha) for the link number',num2str(num+1),' link e.g 10,80 etc'];

disp(link_twist)

al = input(prompt);

link_length = ['Enter the value of offset(d) for the link number',num2str(num+1),' link e.g 1,2,3,4 etc'];

disp(link_length)

prompt = '';

d = input(prompt);

link_offset = ['Enter the value of link length(a) for the link number',num2str(num+1),' link e.g 1,2,3,4 etc'];

disp(link_offset)

prompt = '';

a = input(prompt);

link_theta = ['Enter the value of theta for the link number ',num2str(num+1),' link e.g T1, T2 etc'];

disp(link_theta)

prompt = '';

theta = input(prompt);

Matrix = [cosd(theta) -sind(theta) 0 a;

sind(theta)*cos(al) cosd(theta)*cosd(al) -sind(al) -sind(al)*d; sind(theta)*sind(al) cosd(theta)*sind(al) cosd(al) cosd(al)*d;

0 0 0 1];

disp(matrix_number)

digits(2)

printed_matrix = vpa(Matrix);

pretty(printed_matrix)

num = num+1;

end

matlab

1个回答

1

投票

使用cell array数据类型存储每次运行的整个矩阵。

在while循环之前,您需要预先分配数组Carray = cell([X,1])

然后,您可以使用num值索引数组。您可以选择在增加num后立即放置此行

...

num = num+1

Carray{num} = Matrix

end

现在,您可以通过将索引传递到Carray来访问每次运行生成的Matrix。

Mat3 = Carray{3}

热门问题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值