0

I have a code like that:

[X, Y, Z]= meshgrid(0:5:50, 0:5:50, 0:3:3);
[t1, t2, t3]= meshgrid(35, 25, 3);

A=sqrt((X - t1).^2 + (Y - t2).^2 + (Z - t3).^2);

[rows1,cols1,pages1] = ind2sub(size(A), find(A<=5));

for i=1:1:length(rows1);
    [R1, R2, R3]= meshgrid(cols1(i)*5-5, rows1(i)*5-5, pages1(i)*3-3);
    [reader]=[R1, R2, R3]

    B=sqrt((X1 - R1).^2 + (Y1 - R2).^2 + (Z1 - R3).^2);
    [rowsB,colsB,pagesB] = ind2sub(size(B), find(B<=5));

    for j=1:1:length(rowsB);
        [T1, T2, T3]= meshgrid(colsB(j)*0.2-0.2+0.15, rowsB(j)*0.2-0.2+0.15, pagesB(j)*3-3);
        [tag]=[T1, T2, T3];
    end
end

I need to have all the results from "for" loop because need to apply "intersec" on these results. But i'm facing problem because "for" overwrite the results and i take only the last. How to make smth like

[tag(i)]=[T1, T2, T3] where i is i=1:1:length(rows1).

I have applied smth with pre-allocation but is not working.

2 Answers 2

2

In general you could use cell arrays:

tag = cell(length(rows1),1);
for i=1:length(rows1)
    tag{i} = [T1, T2, T3];
end

Though it looks like a simple matrix would do..

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

Comments

0

In order to assign vectors to rows of a matrix, you will need to slice across columns using a colon for the column index. Something like this:

tag = zeros(length(rows1), 3);
for i = 1:length(rows1)
    ...
    tag(i, :) = [T1, T2, T3];
end

edit: Fixed my example. I misread your code. The above is more general.

Comments

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.