Question on Numbering A1 - An?

how do i make the syntax for looping to have an output of A1, A2, A3, A4... A(n)? cant use A(n) since matlab will read it as an array.

Antworten (2)

Walter Roberson
Walter Roberson am 30 Sep. 2012

2 Stimmen

1 Kommentar

Jan
Jan am 30 Sep. 2012
@James: Such questions are asked such frequently, that they are collected in the FAQ. Please read them carefully.

Melden Sie sich an, um zu kommentieren.

Azzi Abdelmalek
Azzi Abdelmalek am 30 Sep. 2012
Bearbeitet: Azzi Abdelmalek am 30 Sep. 2012

0 Stimmen

  • You can use A(n) if your data are numbers or char (same class),
example:
A=[10 20 30 40 ];
A(1)
A(2)
...
  • use A{n} if your data are both, or same class with different sizes
A={'color','price';'red','100';'green','200'}

3 Kommentare

Portgas Ace
Portgas Ace am 30 Sep. 2012
i need to show A1, A2, A3 to An. which will have its values
sample output:
A1---------3---------5---------6
A2---------5---------3---------4
A3---------6---------7---------9
(sorry for using -, spaces dont work)
If it is just output and not variable names, then
fprintf('A%d', n)
A=[3 5 6;5 3 4;6 7 9] %example
out=[];
for k=1:size(A,1);
out=char(out,[sprintf('A%d ',k) num2str(A(k,:))]);
end
disp(out)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 30 Sep. 2012

Community Treasure Hunt

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

Start Hunting!

Translated by