Problem with creating structure with empty variables and later filling variables with for loop
이전 댓글 표시
Hi everyone!
I have a little problem with the following code, where I first create a structure with the variables I want to use and then later on fill them with a loop. When I fill the variables in the structure with the data from csv_data, the variable-names are overwritten or the structure changes?! I don't really understand what or why this is happening, because working with structures is new to me (and I'm not really a Matlab-Pro to begin with).
Any way I can avoid this problem?
I simplified the code a bit, so you can recreate the problem. Check the struct before and after filling with the loop! Before is how I want it to be (but ultimately filled with data of course!).
csv_data = randn([300 5]);
csv_variables = struct('var',struct('lat', [], 'lon', [], 'A', [], 'B', [], 'C', []));
for i = 1:5;
csv_variables(i).var = csv_data(:,i);
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Structures에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!