Why do I get this error? If i do it in the command window it seems to be possible

Hi everybody, I have a similar problem and I have absolutely no clue where my mistake is. I get the same error but I don´t see why. I am a beginner at Matlab from germany sitting on my bachelor thesis. WIthin the project my goal is to check whether the point is sitting in a bounding box. Therefor I check the first box, which is described by the 8 Points on the Matrix M, with all the 8 points of my component. I then move on to the next box and so on. However if I go into the second box, I get the following error:
This is my Code or at least the part I think is relevant:
Please help me as I said I´m just getting started, so it´s possible I misunderstood something completely.
Thanks a lot guys,
Johnny

7 Comments

Johnny - it's hard to tell from your code screen shot (attaching the m file is easier) but it looks like you have a for loop with
for huellkoper=1:2
M=M{huellkoper};
% etc.
end
Do you really mean to set M to some element of M? It could be that the error is firing on the second iteration when M is no longer a cell array... Should the assigned to variable be named something else?
for huellkoper=1:2
MSubset = M{huellkoper};
% etc.
end
Hi Geoff, Thank you a lot for your quick answer, well I guess I misunderstood something here. What I am trying to do is set m to the second matrix shown in line 24, so the first iteration uses the matrix in line 14 as intended is that right? Why isn't it using the second matrix? What I am basically trying is to do is what is in the inner for loop with 4 different bodies, which i intended to describe as M{1}, M{2},M{3},M{4}... And I wanted to import that somehow and then do it in a loop. Is there any possibility or do I have to do it with different variables? I'm looking forward to your response and as I said I'm a beginner, so I'm very thankful for any advice.
Johnny
If it helps I can upload the file and give a detailed description of what I am trying to do... As I said, big thank you this far
If we had your actual code instead of a picture of part of the code, we could more easily advise you. The part of the code you show does not use M after the M=M{huellkoerper} line.
Thanks a lot for your response here Walter and the response you gave under the other article where I asked this too. I have now attached the code of my problem and I am goint to explain what my idea is. So I am having for bounding boxes which are cuboids. So they have 8 vertices. These vertices are written in the matrix M, so i was trying to have 4 different Matrixes M. My idea was to write them into cell arrays. In the for loop I wanted to count them up. So first iteration with my first bounding box, which I wanted to call M{1} and then count up whats inside the bracket to {huellkoerper} (german for bounding box), so make Huellkoerper=2 and get the second Matrix M{2}. Inside the for loop, I want to look whether the Vertices of my Component K are inside the Bounding Box. Therefor I am putting lines through the vertices of my component to intersect with the plane of my bounding box, described as the Matrix M. I will get 6 intersections per point K with the body of my bounding box, so one in each plane. This worked pretty well in my first iteration for the eight vertices of K which I counted through using "allepunkte". I guess this worked because K is a normal array and not a cell array. After that I want to calculate the distances between the intersection points and my vertices of my component and compare them to each other to see whether I am inside my bounding box. My ultimate goal is to get to know that and if I am outside the bounding box, no matter in the direction of x,y,z, to get that out of Matlab as an Information. The information should tell me how much I have to move the component in the direction of x,y or z to be inside the bounding box and the after I did that do the collision check again.
My idea is now to create different Matrix M1,M2 and the use huellkoerper again to count it up in a for loop. But instead of having a cell array I am going to say if huellkoerper is 1 use M1, elseif 2 use M2 and so on. But what does that mean for my intersection points? Can I still write them into cell arrays?
The intersection points are called spx,spy,spz. Then a 1 or two to decide which one of the planes in the direction it is. SO I got spx1,spx2,spy1,spy2,spz1,spz2. Then are following the braces of the cell array. Using spx1 it would be. spx1{huellkoerper}{allepunkte}. So I want to know inside which body M I check and which of the vertices of my Component K I am checking.
As I said I am so grateful for your help everybody I am really looking forward to your response! If you have ideas how to do that easier or more intelligent it would be nice too. As I said I´m unexperienced and that is the first solution that came to my mind.
Have a nice weekend and thanks for your work in advance!
Johnny
Your code does not use M after the M=M{huellkoerper}; line, so it is difficult to understand how M fits with the rest of your code.
My idea is now to create different Matrix M1,M2 and the use huellkoerper again to count it up in a for loop. But instead of having a cell array I am going to say if huellkoerper is 1 use M1, elseif 2 use M2 and so on
NO! Just use M{huellkoerper} in the part of your code that you want the appropriate matrix!
Wow you are right the solution is changing M=M{huellkorper}; to just M{huellkoerper};
So that's what you meant earlier I just wasn't getting it...
Thank you a lot Walter you are a genius! Helped me out a lot! That was a lot easier than I expected. Big thank you once again! Hope I can count on your advice if I need it again in the future.
Have a nice weekend,
Johnny

Sign in to comment.

 Accepted Answer

Inside a for loop, you are assigning
M = M{INDEX}
That replaces all of M with the contents of one cell of M. Afterwards, M is unlikely to be a cell array.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products

Tags

Community Treasure Hunt

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

Start Hunting!