for example my output: 20 30 40 50 I want to convert ---------------> A(0)=20 <--------------- A(1)=30 A(2)=40 A(3)=50 how can I make this??

 采纳的回答

Walter Roberson
Walter Roberson 2011-12-9

0 个投票

A = [20 30 40 50];
fprintf(1, 'A(%d)=%d ', [(0:length(A)-1).' ; A(:)].' );
fprintf(1, '\n');

5 个评论

r?za çay
r?za çay 2011-12-9
thanks:)
r?za çay
r?za çay 2011-12-10
unfortunately does not work correctly.actually
my program has this output:
A= 30 40 20 10 70 but I want to convert these: A(0)=30 A(1)=40 A(2)=20 A(3)=10 A(4)=70 your program give different value for example: A(0)=1 A(1)=2 A(2)=3......
Paulo Silva
Paulo Silva 2011-12-10
I can't seem to fix Walter code but here's one way to do it
A = [20 30 40 50];
for n=1:numel(A)
fprintf('A(%d)=%d ', n-1 , A(n) );
end
fprintf('\n');
Walter Roberson
Walter Roberson 2011-12-10
Hmmm... I did test at the time I posted.
Did you perhaps omit the ".'" after the [] ?
r?za çay
r?za çay 2011-12-11
ohhhh Paulo this program work well. very thanks Paulo and Walter:))

请先登录,再进行评论。

更多回答(1 个)

Paulo Silva
Paulo Silva 2011-12-9

0 个投票

A=[20 30 40 50]
MATLAB index values start at 1 not 0

2 个评论

Paulo, did you not upgrade to the Purple Agate beta of the Mind Reading Toolbox ? "It assists in allowing trust with your own intuition and opens the spiritual flood gates to a realm of endless possibilities." Are you still using the Amber beta ?
Paulo Silva
Paulo Silva 2011-12-10
I'm always using old versions but will upgrade soon, both MATLAB version and Mind Reading Toolbox ;)

请先登录,再进行评论。

类别

在 帮助中心 和 File Exchange 中查找有关 Construct and Work with Object Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by