simple syntax problem need help "curly braces"

Im completely confused what matlab is doing here
Can someone tell me
I tried using help file but don't get what its talking about
A(2,1) = {[1 2 3; 4 5 6]}
What is this thing doing?
If i ask it what A is i get
ans =
[2x3 double]
How do i index A properly to get back to my data?
Is this making a structure of some sort? If i ask it was A(1,1) is it tells me the same answer
So what are the curly braces doing here? Thanks in advance

답변 (1개)

Walter Roberson
Walter Roberson 2016년 5월 1일

0 개 추천

A{1} would get you back the 2 x 3 matrix.

댓글 수: 7

Robert
Robert 2016년 5월 1일
So when you say A{2,1} that is creating a cell array data type correct
OF what size? Is the cell array like a metrix
so should i think of a cell array as like a table of sorts? with storage bins?
2 rows one column but in each bin you can put entire matrixes?
A = cell(2,1) would create a cell array that is 2 rows one column.
A{2,1} = something would store the something in the second row column 1 of A. Just like with a numeric array, if necessary A will be grown to hold the entry.
You can find the size of the cell array using size().
Each entry of a cell array can contain a different size and data type.
You could think of a "chest of drawers", something like the top part of
Robert
Robert 2016년 5월 1일
편집: Robert 2016년 5월 1일
Thanks for the reply
So what is this one doing then?
A(2,1) = {[1 2 3; 4 5 6]}
Also
E = {3*x-y==2 , x+y == 1};
I understand that E will expand as required but E = something in curly braces? So is this saying, E is a cell array of 1,2 size and in 1,1 is the string that is the first equation and the 1,2 is the string that is the second equation.
I saw your other post on solving systems symbolically. If matlab is going to remove the ability for the solve function to handle strings then how are you suppose to enter them? It sounds completely futile to me
That is equivalent to
A{2,1} = [1 2 3; 4 5 6];
It is storing the 2 x 3 matrix into the second row first row of the cell array.
Robert, I really feel that reading the FAQ would help you http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F. I think it will give you a good idea of how cells work and when to use braces, brackets, and parentheses. Granted, cell arrays are confusing and the FAQ will help. By the way, have you considered using a simpler variable with far less overhead? It's called a table and is good if all the things in a single column are a single type of variable, like a number. Cell arrays are good if the size or type of your variable varies on an element-by element basis, so it's more flexible than tables but far more complicated.
Stephen23
Stephen23 2016년 5월 2일
편집: Stephen23 2016년 5월 2일
"but far more complicated"
I think slightly more complicated would be a better adjective.
Cell arrays are not confusing. They are just boxes, into which things can be placed (and later removed). What is so complicated about that?
Trust me - they're one of the most confusing variables in MATLAB. We see it here everyday with users not knowing how to use them. You know that's true. Maybe not complicated for us, but for new users they're complicated - the daily evidence speaks for itself.

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2016년 5월 1일

댓글:

2016년 5월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by