How to declare above type of variable in MATLAB?

1 次查看(过去 30 天)
n = {[1,2] [1,6] [2,3] [2,6] [3,4] [3,6] [4,5] [4,6] [5,6]}
How to declare above type of variable in MATLAB?
  4 个评论
Gaurab Raj Neupane
Gaurab Raj Neupane 2020-9-30
How can I declare the above type of variable before hand and fill up the numbers in loop?
Gaurab Raj Neupane
Gaurab Raj Neupane 2020-9-30
编辑:Gaurab Raj Neupane 2020-9-30
Like for getting the matrix A=[1,2,3]
i could declare A= zeros(1,3) then fill the matrix/vector using for loop like
for ii = 1 :3
A(1,ii)=ii;
end
Similarly, how can i declare the matrix like I have done; A= zeros(1,3) for the final output n = {[1,2] [1,6] [2,3] [2,6] [3,4] [3,6] [4,5] [4,6] [5,6]} ?

请先登录,再进行评论。

采纳的回答

Stephen23
Stephen23 2020-9-30
"How can I declare the above type of variable before hand and fill up the numbers in loop?"
n = cell(1,9);
for k = 1:9
n{k} = [val1,val2];
end

更多回答(1 个)

Ameer Hamza
Ameer Hamza 2020-9-30
An alternative is to use mat2cell() like this
x = [1 2 3 4 5 6 7 8]; % example values
C = mat2cell(x, 1, 2*ones(1,numel(x)/2));

类别

Help CenterFile Exchange 中查找有关 Model Upgrades 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by