1

For example

A = {{1,2},{23,34},{45,4},...}

How to create such a data type in MATLAB

How to access the i-th element and the elements within it?

For Ex. A[2] should return {23,34} and A[2].1 should return 23.

1 Answer 1

2
A = {{1,2},{23,34},{45,4},...}

is valid MATLAB syntax, if you are trying to make a cell array of cell arrays. However, you'd probably want to store vectors rather than arrays in your array:

A = {[1,2],[23,34],[45,4],...}

Access them like A{2} or A(2) but far more likely the first one. If you want an individual element then A{2}(1)

But if every one of your cells is going to contain a 2 element vector then you will have a much easier time just using a 2D matrix:

A = [1,2;23,34;45,4;,...]

And and now access the entire row i.e. A(2,:) or for an individual element A(2,1)

Sign up to request clarification or add additional context in comments.

1 Comment

Additional Information. I was trying to populate data of coordinate points obtained from an image for further calculations. Ex. of .m (matlab file) for the above question will look like... for c = 1:max_c for r = 1:max_r // Any condition you maybe want to check A(count,:) = [c,r] // count = count+1 end end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.