how to Vectorize this for loop
显示 更早的评论
Hi everyone i have wrote this code and i want to vectorize my code so it run faster here is the part of code i'm talking about
fileID = fopen('CANDec(day_1_9).txt','r');
text_data = textscan(fileID,'%s %s %s %s %s %s %s %s',1000,'delimiter',';');
hex=text_data(:,4);
signal_name=text_data(:,7);
decimal_wert=text_data(:,8);
for i =1:length(text_data{1,1})
can.(signal_name{1,1}{i,1}).hex{i,1}=hex{1,1}{i,1};
can.(signal_name{1,1}{i,1}).decimal_wert{i,1}=decimal_wert{1,1}{i,1};
end
hex , signal_name and decimal_wert are cells that i read from a .txt file (CANDec(day_1_9)). it has actually many million lines . it's means there is millions of signal_name but here i read just 1000 lines.
now i'm building a structure can and as the name for substructures i use signal_name dynamically. if you go in can-structure you see all signal_name as substructure and in these substruct you find again 2 substruct with the names hex and decimal_wer.
i hope you understand the code . so my goal is to vectorize this for loop . when i remove the for and vectorize it simply I will get this error :
Expected one output from a curly brace or dot indexing expression, but there were 1000 results.
i =1:length(text_data{1,1})
can.(signal_name{1,1}{i,1}).hex{i,1}=hex{1,1}{i,1};
can.(signal_name{1,1}{i,1}).decimal_wert{i,1}=decimal_wert{1,1}{i,1};
i hope you can help me with that.
Thank you
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!