Creating data structures in loop for later reference, loop is deleting all but last entry.

3 views (last 30 days)
I am attempting to make a script which will pull NURBS data from Blender text file, I have managed to extract the control points for the generation of the structure. But, I need it to perform the generation automatically. I made a loop which runs the function and puts the result into a cell array, that way I call later call on it as " crv{1},crv{2}" etc. and for graphing purposes.
However, each time I run the script, it will only keep the last loop results and result in my "crv" cell array saying "1x7" but then listing the results as " [] [] [] [] [] [] [1x1 struc]" if I run it for 7 loops, the data is properly recorded in the last entry but all of the others are empty.
Unless you have the NURBS/Geopdes package installed, running the code yourself will not work.
I would like to know if their is a better way to create structures in a loop than this, I know dynamically creating variables is a huge no-no, but I can't think of what else to do if the cell array method doesn't work.
<<
>>
close all; clear; clc;
content = fileread( 'TEST_CUBE.txt' ) ;
expr = '[^\n]*v [^\n]*';
matches = regexp(content,expr,'match');
n = numel(matches);
for i = 1:n
expression = 'v ';
replace = '';
matches(i) = regexprep(matches(i),expression,replace);
end
for ii = 1:n
for i = ii
C = cell2mat(matches(i));
end
NUM = str2num(C);
Ctrl{i} = NUM;
end
for i = (n-1)
crv{i} = nrbline([Ctrl{1,i}(1,1) Ctrl{1,i}(1,2) Ctrl{1,i}(1,3)],[Ctrl{1,i+1}(1,1) Ctrl{1,i+1}(1,2) Ctrl{1,i+1}(1,3)]);
nrbctrlplot(crv{i});hold on;
end

Accepted Answer

Walter Roberson
Walter Roberson on 28 Jan 2018
Are you sure you want
for i = (n-1)
which executes only for the single value (n-1) ? Perhaps you want 1:n-1 ?

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!