Summation with increasing index

조회 수: 1 (최근 30일)
CBde
CBde 2017년 1월 14일
답변: Wilson A N 2017년 1월 17일
Hello,
what I'm trying to do is probably quite simple, but I havn't gotten it up till now. I have a large quantity of data in the form of u1=2, u2=5, etc... and I want to basically get the average value of certain amount of u's, but I don't know how to specifyn these certain amounts in Matlab, because it only works with the form u(1) and not u1 when I try to make a loop with the index increasing.

답변 (1개)

Wilson A N
Wilson A N 2017년 1월 17일
You can do variables in the form of u1, u2, etc as shown below:
for i = 1:10
var{i} = ['u', num2str(i)];
end
If you try to access var{i} then you get a string. Now you can access the corresponding variable referred to by var{i} by using the 'eval' function. Please check the link given below for the eval function below:

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by