creating a loop for a specific computation
Ältere Kommentare anzeigen
tCOD=readtable(full_file_name,'FileType','text', ...
'headerlines',end_of_header_line,'readvariablenames',0);
all_time=tCOD{:,3:8};
all_time_second= all_time(:,4)*3600+all_time(:,5)*60+all_time(:,6); % seconds
unique_seconds=unique(all_time_second);
The attached data file can be read by the above codes and "unique_seconds" variable can be created correctly. When multiple data files are involved, I used the following codes;
for j=1:num_of_files
tCOD{j,:}=readtable(full_file_name(j,:),'FileType','text', ...
'headerlines',end_of_header_line(j),'readvariablenames',0);
end
all_time_0=vertcat(tCOD{:});
all_time=all_time_0{:,3:8};
all_time_second= all_time(:,4)*3600+all_time(:,5)*60+all_time(:,6); % seconds
For multiple files, all_time_second consists of n x 1 array where n equals the row numbers of tCOD.
for k=1:num_of_files
[a(k),b(k)]=size(tCOD{k,:});
end
where a consists of row size of each tCOD array (378063 and 377840 for two different data files). I need to apply unique(all_time_second) command for each independent n x 1 array from tCOD as follows;
for example if two files are read;
unique_seconds_1=unique(all_time_second(1:a(1)));
unique_seconds_2=unique(all_time_second(a(1)+1:a(1)+a(2)));
for example if three files are read;
unique_seconds_1=unique(all_time_second(1:a(1)));
unique_seconds_2=unique(all_time_second(a(1)+1:a(1)+a(2)));
unique_seconds_3=unique(all_time_second(a(1)+a(2)+1:a(1)+a(2)+a(3)));
How I can create a loop or something else to create unique_seconds arrays w.r.t. the file numbers without explicitly writing unique_seconds_i?
I attached the one representative data file.
8 Kommentare
dpb
am 31 Jul. 2021
No idea what you're trying to do here...explain to us what the end result is intended to be -- it would probably be simplest to create a small data set that shows input and expected output and if not obvious, how the output is derived from the inputs.
It is not at all clear what the point of unique() and size() are -- the unique values in data() will be some set of numbers, those included in different subsections of the vector would be determinable by simply one set of indices.
Explain what it is that are trying to do...
sermet OGUTCU
am 31 Jul. 2021
Bearbeitet: sermet OGUTCU
am 31 Jul. 2021
Image Analyst
am 31 Jul. 2021
Did you see where he said "create a small data set that shows input and expected output"?
Again, please attach a specific example using smaller numbers if you still need help.
sermet OGUTCU
am 31 Jul. 2021
dpb
am 31 Jul. 2021
Just edit in place or add to it...even a verbal description of what the end object is might be sufficient; I/we could make some assumptions, but a clear definition would be bester... :)
sermet OGUTCU
am 31 Jul. 2021
dpb
am 31 Jul. 2021
OK. But... :) (always a rhetorical "but" isn't there... <VBG>)
One could do something like that, but instead let me ask what the purpose in building those vectors of unique times is? Are you wanting to merge/select data from the various files on the basis of matching them? If so, there are much simpler ways to do so that don't rely on building such arrays.
Also, you don't need the sizes() arrays and the linear indexing even to do whaty you are doing -- set membership functions such as intersect() are vectorized and would work over the indivdual file content without the combining of the data.
But, before we go down that rabbit hole with Alice, let's also make sure we can't just go to the tea party instead... :)
sermet OGUTCU
am 1 Aug. 2021
Bearbeitet: sermet OGUTCU
am 1 Aug. 2021
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Structures finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!