create a struct with two columns
20 次查看(过去 30 天)
显示 更早的评论
Hi. I want to create a structure like the one in the figure consisting of two columns: 'name' and 'folder'.
I already have the char (created by a for loop) of:
for k = 1:7
name_char % = '0001';
folder_char %= 'C\.....';
end
I tried to create the structure but I don't know how to insert all the values inside name_char and folder_char generated by the for loop.
first_column = 'name_char';
second_column = 'folder_char';
s = struct(first_column,name_char,second_column,folder_char);
How can I do it?
1 个评论
Stephen23
2023-6-14
"Hi. I want to create a structure like the one in the figure consisting of two columns: 'name' and 'folder'."
Actually your structure has exactly one column, and six fields. This is clearly shown in the screenshot.
Do not confuse the number of fields with the size of a structure, they are completely unrelated.
采纳的回答
Stephen23
2023-6-14
"How can I do it?"
S = struct([]);
for k = 1:7
name_char % = '0001';
folder_char %= 'C\.....';
S(k).name = name_char;
S(k).folder = folder_char;
end
0 个评论
更多回答(1 个)
Satwik
2023-6-14
for k = 1:7
name_char = '0001';
folder_char = 'C\.....';
end
first_column = 'name_char';
second_column = 'folder_char';
s = struct('first_column',{name_char},'second_column',{folder_char});
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!