1

i am creating a multidimensional array in matlab which has three paramter , number , width and height

A = randn(number,width,height)

My problem is number is dynamic variable which increase when it find objects in the text file. How i am suppose to make the number variable dynamic,

I tried this but it didnt worked

A = randn(:,width,height)
5
  • First you should find number, then you should call randn. Commented Feb 8, 2013 at 10:09
  • I cant , its like words are hidden in a text file. it can be zero or can be maximum. Commented Feb 8, 2013 at 10:10
  • Can you then give a description of your variables and a stepwise explanation of what you are trying to do? This is not enough information to help you. Commented Feb 8, 2013 at 10:11
  • Do you need the data to be normally distributed over all the matrix, or you just chose randn to create a matrix as if it is zeros or ones? Commented Feb 8, 2013 at 10:41
  • I am creating a empty matrix of dimension 3, and popualting with random number, in future in will fill it with the data coming from a text file. I know the object size (width and height) but dont know how much objects are these Commented Feb 8, 2013 at 10:44

2 Answers 2

3
i = 0;
when (object in text file)
i = i+1;
A(i,:,:) = data;
end

data is of size - width x height

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

1 Comment

or just append A = []; while A = [A; data] end here the size is (number x width, height) You can later make it 3D matrix using reshape....
1

first count the number and then allocate the matrix accordingly.

i = 0;
when (object in text file)
i = i+1;
end

A = randn(i,width,height);

2 Comments

but then i have to run the loop again to get the objects.
I thought you just needed to count the objects. You can get them during the first loop.

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.