Changing Variable in matrix

22 ビュー (過去 30 日間)
Yoga Arviansyah
Yoga Arviansyah 2019 年 10 月 30 日
回答済み: Tianhao Zhang 2019 年 10 月 30 日
How to change variable into number in matrix, for example I have A=[a b c]: Then i declare a = 1 b = 2 c = 3 So matrix will be A = [1 2 3]
Thank you

回答 (2 件)

Bob Thompson
Bob Thompson 2019 年 10 月 30 日
Why are you originally defining A as A = [a b c]? This isn't very common or efficient matlab usage. I would suggest starting with A = [1 2 3] and adjusting the values as needed. As for the change, see below.
% Defining A
A = [1 2 3];
% Changing A to 2 4 6
A = [2 4 6];
% or
A(1) = 2;
A(2) = 4;
A(3) = 6;

Tianhao Zhang
Tianhao Zhang 2019 年 10 月 30 日
Like this?
a = 1;
b = 2;
c = 3;
A = [a b c]

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by