indexing my answer into matrix form

1 次查看(过去 30 天)
how do i display my answer that is x0 (which is a 3x1 matrix) into a matrix where the rows are my x0 and the columns are my i,(number of iteration)
  2 个评论
Muqhairie Marzuki
Muqhairie Marzuki 2020-12-24
okay so i have my final answer that is after solving a system of linear equation my answer should be a matrix of 3x1 that is the values of x,y and z respectively. so what i want to know is how do i display that in a form of matrix where the number of rows represents the variables and the number columns represents the number of iteraions, i which is also included in my calculator

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2020-12-24
编辑:Walter Roberson 2020-12-24
format long g
for i = 1 : 10
%x0 = some calculation involving values indexed at i that gives a vector of length 3
x0 = [sin(2*pi*i+i/2), -cos(2*pi*i-i/2), cos(2*pi*i+i/2)*sin(2*pi*i-i/2)];
results(:,i) = x0;
end
disp(results)
Columns 1 through 6 0.479425538604203 0.841470984807896 0.997494986604054 0.909297426825682 0.598472144103957 0.141120008059869 -0.877582561890373 -0.540302305868139 -0.0707372016677022 0.416146836547143 0.801143615546934 0.989992496600446 -0.420735492403949 -0.454648713412841 -0.0705600040299343 0.378401247653963 0.479462137331568 0.139707749099461 Columns 7 through 10 -0.350783227689618 -0.756802495307927 -0.977530117665097 -0.958924274663139 0.936456687290796 0.65364362086361 0.210795799430778 -0.283662185463229 -0.328493299359396 -0.494679123311693 -0.20605924262088 0.272010555444682
t = array2table(results, 'rownames', {'x', 'y', 'z'}, 'VariableNames', "t="+string(1:size(results,2)))
t = 3x10 table
t=1 t=2 t=3 t=4 t=5 t=6 t=7 t=8 t=9 t=10 __________________ __________________ ___________________ _________________ _________________ _________________ __________________ __________________ __________________ __________________ x 0.479425538604203 0.841470984807896 0.997494986604054 0.909297426825682 0.598472144103957 0.141120008059869 -0.350783227689618 -0.756802495307927 -0.977530117665097 -0.958924274663139 y -0.877582561890373 -0.540302305868139 -0.0707372016677022 0.416146836547143 0.801143615546934 0.989992496600446 0.936456687290796 0.65364362086361 0.210795799430778 -0.283662185463229 z -0.420735492403949 -0.454648713412841 -0.0705600040299343 0.378401247653963 0.479462137331568 0.139707749099461 -0.328493299359396 -0.494679123311693 -0.20605924262088 0.272010555444682

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by