How to take data from multiple variables and store them in one variable?

조회 수: 22 (최근 30일)
suppose, I have 3 variables containg some data but I want to store all the datas of the 3 separate variables in a single variable.

채택된 답변

Star Strider
Star Strider 2022년 7월 5일
I am not certain what you want, however one option would be a cell array —
v1 = rand(3)
v1 = 3×3
0.5133 0.6163 0.4846 0.3344 0.3004 0.8163 0.8754 0.6556 0.6720
v2 = 'This is Variable #2'
v2 = 'This is Variable #2'
v3 = exp(v1)
v3 = 3×3
1.6708 1.8521 1.6235 1.3971 1.3504 2.2622 2.3999 1.9263 1.9581
V = {v1, v2, v3}
V = 1×3 cell array
{3×3 double} {'This is Variable #2'} {3×3 double}
.

추가 답변 (1개)

John D'Errico
John D'Errico 2022년 7월 5일
편집: John D'Errico 2022년 7월 5일
Essentially, you just need to learn MATLAB. Read the various tutorials you can find. In there you would learn about the various variable classes available.
There are structs.
A.num = 1:5;
A.str = "The quick brown fox";
A.mat = rand(2);
A
A = struct with fields:
num: [1 2 3 4 5] str: "The quick brown fox" mat: [2×2 double]
There re cell arrays.
B = cell(1,3);
B{1} = 1:5;
B{2} = "The quick brown fox";
B{3} = rand(2);
B
B = 1×3 cell array
{[1 2 3 4 5]} {["The quick brown fox"]} {2×2 double}
There are simple arrays.
C = zeros(3,3);
C(1,:) = ones(1,3);
C(2,:) = 1:3;
C(3,:) = rand(1,3);
C
C = 3×3
1.0000 1.0000 1.0000 1.0000 2.0000 3.0000 0.4258 0.5060 0.8791

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by