Create a vector name from two integer variables

Hi,
I want to create a vector name from two integer variables. For example I have two for loops
for i=1:N for j=1:M
and I want to create a vector called vectorij, i.e: vector12, vector 13 and so on. Thanks

댓글 수: 3

I tried some of your proposal but I got some other things :)
What I try it is I have a matrix of (N,M) which I want to split it in column vectors, called as vector(column, row) containg the values of the matrix (column,row)..
Jan
Jan 2013년 9월 9일
I do not understand, what you are looking for. Could you provide an explicit example with real data?
For example:
I have the A matrix, which changes during 3 iterations like:
Iteration 1 A1=[1 2 3 4; 5 6 7 8];
Iteration 2 A2=[3 5 3 4; 6 6 7 9];
Iteration3 A3=[3 2 3 5; 1 6 4 8];
Then I want to obtain the equivalent vectors associated with the upper 3 matrices
vector11=[1,5]; vector12=[2,6]; .............. vector22=[5,6]; vector23=[3,7]; .............. vector33=[3,4]; vector34=[5,8];
and I want that my vector to have the name: vector_Iteration_No_Column A matrix for example vector34 is vector_Iteration3_Column4
Hope now is much clear :)

댓글을 달려면 로그인하십시오.

답변 (3개)

James Tursa
James Tursa 2013년 9월 9일

2 개 추천

댓글 수: 2

Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 9일
편집: Azzi Abdelmalek 2013년 9월 9일
I think he is not asking for variables name, just a cell array of stings
Jan
Jan 2013년 9월 9일
No, "vector11=[1,5]" from the comment looks, like names are wanted.

댓글을 달려면 로그인하십시오.

Jan
Jan 2013년 9월 9일
편집: Jan 2013년 9월 9일

1 개 추천

Hiding the indices inside the names of variables is really cruel. Don't do this. You'd never do this in the real life. Names are names, data are data.
A{1} = [1 2 3 4; 5 6 7 8];
A{2} = [3 5 3 4; 6 6 7 9];
A{3} = [3 2 3 5; 1 6 4 8];
Now write instead of "vector11":
A{1}(:, 1)
Or general instead of "vector_ij_":
A{i}(:, j)
This is fast, easy to expand to billions of iterations and fast to process. Using a 3D-array might be even faster, if the elements of A have all the same size.
Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 9일
편집: Azzi Abdelmalek 2013년 9월 9일

0 개 추천

This is a vector of names
out={};
for k=1:5
for p=1:5
out{end+1}=sprintf('vector%d%d',k,p)
end
end

댓글 수: 3

regexp(sprintf('vector%i%i\nS',fullfact([5 5])'),'S','split')'
:)
What is mean by something like this name= []?
It sets the variable called "name" to null, or empty. It still exists, it's just that it has no value at all. Doing that to a row of a matrix will delete that row from the matrix, shortening it.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2013년 9월 9일

댓글:

2018년 8월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by