in the above question l=a[i][j] value i.e l=1 and m=a[i][j+1] value i.e m=6; and so on..... is the required answer. Please provide the code if exist
[l m]=a(1,2,3;6,7,8) in matlab..........
8 ビュー (過去 30 日間)
古いコメントを表示
is it possible to assign the elements of matrix a to [l m]?
2 件のコメント
Jan
2017 年 5 月 10 日
The question is not clear and the comment confuses me even more. What is "a[i][j]"? It is no valid Matlab syntax, but please do not let us guess if you mean C code or any other notation. Explain clearly what you want to get. "m=a[i][j+1] value i.e m=6"???
回答 (1 件)
KL
2017 年 5 月 10 日
- You cannot assign two variables in one command unless it's a function return.
- To define an array you should use "Square braces" --> [ ]
- Then if you want to access the elements of a matrix, it goes like matrix_name(rowIndex, columnIndex))
For your case,
>> a = [1,2,3;6,7,8]
a =
1 2 3
6 7 8
>> l = a(1,1)
l =
1
>> m = a(2,1)
m =
6
In case you want all the values in the first row on l and second row on m, then
>> l = a(1,:)
l =
1 2 3
>> m = a(2,:)
m =
6 7 8
here : means all elements in the specified rowIndex.
3 件のコメント
KL
2017 年 5 月 10 日
Thanks for the links Stephen. Yes, I'm familar with cell array returns while accessing its contents (as opposed to matrices). I'm just wondering, does it really make a difference calling it array concatenation? after all, we're creating a new array by using the square brackets, I think. Having said that, I appreciate you pushing people learn the better way.
Stephen23
2017 年 5 月 10 日
"does it really make a difference calling it array concatenation?"
We regularly get questions here where people want to create lists (which MATLAB does not have), and they often mistake the [] operator for a list operator. It does cause some confusion for them. I believe that clarifying the concatenation role helps beginners to understand that all numeric values are arrays (even scalar arrays (aka "numbers")), as arrays are a first-class type in MATLAB.
So while the difference might be subtle and small, I think it is a point that is worth making, in order to understand MATLAB better.
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!