You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
read and store data from struct file during each iteration in the for loop
5 views (last 30 days)
Show older comments
Hi,
I have a for loop as shown. During each iteration the will store entire output in the struct file named Measurements. (file attached here)
From this struct file file, I need to read and store only 'Centroid', 'Eccentricity', 'EquivDiameter' in the sepearte array.
for i = 1:1:1000
% some operation
Measurements = some operation
end
Accepted Answer
Star Strider
on 4 May 2024
I am not certain what result you want.
Try this —
% load('matlab')
% whos('-file', 'matlab')
%
% Measurements
fields = {'Centroid', 'Eccentricity', 'EquivDiameter'};
files = dir('*.mat');
NrFiles = numel(files);
for k = 1:NrFiles
LD = load(files(k).name);
MeasTable = struct2table(LD.Measurements);
VN = MeasTable.Properties.VariableNames;
ColNrs = find(ismember(VN,fields));
ForFile = MeasTable(:,ColNrs);
writetable(ForFile,sprintf('NewTable%04d.txt',k))
end
readtable('NewTable0001.txt')
If all the .mat files have the same internal structure, then ‘MeasTable’ also will, and some of the lines in the loop can be defined prior to it.
.
20 Comments
Turbulence Analysis
on 4 May 2024
Thanks!
Actually this code is a part of image processing. I am processing 5000 images in the for loop. For each image in the for loop, the below command will generate Measurements struct file. From that file I need to store only 'Centroid', 'Eccentricity', 'EquivDiameter' in the seperate array, lets say 'A'. Then the data will append in the array 'A' for sequence of images in the for loop.
By doing this I may reach the memory limit, however I am running this in the HPC, so that shouldn't be a problem
for i =1:1:500
%% do image processing
Measurements = regionprops(mask, 'all');
end
Turbulence Analysis
on 4 May 2024
And forgot to mention, teh size of the Measurements struct file will different during each iteration..
Star Strider
on 4 May 2024
My pleasure!
The variable column sizes can vary so long as within each file they are all the same sizes. If the structures are in different orders, esch table derived from them will be different in each iteration, and that could cause problems with my code as currently written. However it would be straightforward to have all the table arrays be saved in the same column orientation, regardlkess of their initial orientation. (I need to know if that is an issue.)
The table arrays can be vertically concatenated to produce one table as the final result, if that is what you want.
However, I’m still not sure what you want as the result. Saving the arrays as a single table is certainly possible.
Turbulence Analysis
on 4 May 2024
Thanks again!
Now, I am saving the struct file gnerated during each for loop iteration in the cell array C3.
Then I modifed your code as follows, however I a couldn't concatenate to get one table.
The overall idea is to create one table which stores all the results generated duirng each for loop iteration
fields = {'Centroid', 'Eccentricity', 'EquivDiameter'};
% files = dir('*.mat');
% NrFiles = numel(files);
for k = 1:3
LD = (c3{1,k});
MeasTable = struct2table(LD);
VN = MeasTable.Properties.VariableNames;
ColNrs = find(ismember(VN,fields));
ForFile = MeasTable(:,ColNrs);
writetable(ForFile,sprintf('NewTable%04d.txt',k));
end
Turbulence Analysis
on 4 May 2024
Actually, the above operation saves three new tables NewTable0001.txt; NewTable0002.txt; NewTable0003.txt, how to combine them to a single table?
Star Strider
on 4 May 2024
As always, my pleasure!
To get one table (assuming all the variables are the same in each ‘ForFile’ table) create a column-oriented collection of them using:
ForFile{k,:} = MeasTable(:,ColNrs);
and then concatenate that at the end —
load('matlab') % Information (Delete Later)
whos('-file', 'matlab') % Information (Delete Later)
Name Size Bytes Class Attributes
c3 1x3 446028 cell
fields = {'Centroid', 'Eccentricity', 'EquivDiameter'};
% files = dir('*.mat');
% NrFiles = numel(files);
for k = 1:3
LD = c3{k};
MeasTable = struct2table(LD);
VN = MeasTable.Properties.VariableNames;
ColNrs = find(ismember(VN,fields));
ForFile{k,:} = MeasTable(:,ColNrs);
end
ForFile{:} % Information (Delete Later)
ans = 5x3 table
Centroid Eccentricity EquivDiameter
________________ ____________ _____________
348.91 699.7 0.81707 47.014
345.18 899.77 0.40595 29.468
352.85 455.82 0.51376 35.414
347.92 547.24 0.52267 25.805
360.68 659.78 0.43788 8.7404
ans = 5x3 table
Centroid Eccentricity EquivDiameter
________________ ____________ _____________
348.8 702.4 0.82225 46.96
345.02 903.09 0.44569 29.403
352.75 458.27 0.56003 35.252
347.88 550.03 0.5379 25.904
360.95 663.25 0.4336 8.7404
ans = 6x3 table
Centroid Eccentricity EquivDiameter
________________ ____________ _____________
348.75 705.11 0.82348 46.906
345.03 906.35 0.4668 29.316
352.64 460.75 0.58144 35.234
351.56 346.11 0.54136 31.855
347.92 552.75 0.54632 25.953
361 666.5 0.43593 8.7404
Combined = vertcat(ForFile{:})
Combined = 16x3 table
Centroid Eccentricity EquivDiameter
________________ ____________ _____________
348.91 699.7 0.81707 47.014
345.18 899.77 0.40595 29.468
352.85 455.82 0.51376 35.414
347.92 547.24 0.52267 25.805
360.68 659.78 0.43788 8.7404
348.8 702.4 0.82225 46.96
345.02 903.09 0.44569 29.403
352.75 458.27 0.56003 35.252
347.88 550.03 0.5379 25.904
360.95 663.25 0.4336 8.7404
348.75 705.11 0.82348 46.906
345.03 906.35 0.4668 29.316
352.64 460.75 0.58144 35.234
351.56 346.11 0.54136 31.855
347.92 552.75 0.54632 25.953
361 666.5 0.43593 8.7404
writetable(Combined,'Combined.txt');
Check = readtable('Combined.txt') % Check Result
Check = 16x4 table
Centroid_1 Centroid_2 Eccentricity EquivDiameter
__________ __________ ____________ _____________
348.91 699.7 0.81707 47.014
345.18 899.77 0.40595 29.468
352.85 455.82 0.51376 35.414
347.92 547.24 0.52267 25.805
360.68 659.78 0.43788 8.7404
348.8 702.4 0.82225 46.96
345.02 903.09 0.44569 29.403
352.75 458.27 0.56003 35.252
347.88 550.03 0.5379 25.904
360.95 663.25 0.4336 8.7404
348.75 705.11 0.82348 46.906
345.03 906.35 0.4668 29.316
352.64 460.75 0.58144 35.234
351.56 346.11 0.54136 31.855
347.92 552.75 0.54632 25.953
361 666.5 0.43593 8.7404
I needed to understand what ‘c3’ is and how to work with it in order to check my code to be sure it works correctly with it. (It does.)
It is easier (and probably more efficient) to concatenate the ‘ForFile’ tables at the end rather than concatenate them in the loop.
You can sefely delete the lines I commented, since they are for my information only in order for me to understand your new .mat file and to work with its contents.
This was interesting!
.
Turbulence Analysis
on 5 May 2024
Hi,
In the 'c3' file some struct files has a size of 1x1, I am getting the below error whenever it reads those file
Error using struct2table
Input structure is a scalar, but its fields have different numbers of rows. If
you intended to create a table with one row, set 'AsArray' to true.
code
for k = 1:1
LD = c3{k};
MeasTable = struct2table(LD);
VN = MeasTable.Properties.VariableNames;
ColNrs = find(ismember(VN,fields));
ForFile{k,:} = MeasTable(:,ColNrs);
end
Star Strider
on 5 May 2024
I have never gotten that error before.
Adding a conditional test using structfun could work. The problem is that if the three desired variables have different numbers of rows, it would be necessary to either pad the missing rows with NaN or truncate the longer rows to the lengths of the shorter rows. Since only the three desired variables actually ‘count’, using structfun to determine if they are all the same row lengths could be appropriate.
The error suggests using AsArray, however after reading the documentation on it, it would likely not work the way it needs to here, and an alternative would have to be designed.
I need that particular structure (and if possible some others that throw the same error to see if there is any common problem amongst them) in order to design a work-around.
Meanwhile, in the event that the three desired variables have different numbers of rows, would you want to expand the shorter ones filling the empty rows with NaN, or truncate the longer ones? The table will not work if they have different numbers of rows.
Turbulence Analysis
on 5 May 2024
for e.g. in the attached c3, it works well from k = 1 to 243, however it throws error at k = 244 as it is 1x1
Star Strider
on 5 May 2024
That one errant structure managed to defeat what I considered a reasonably efficient approach to this. The problem is that structures do not index as other array types do, so I had to revert to a different approach. I am not sure if it is more efficient than my original approach, however it appear to work correctly and reads and processes all 245 elements of ‘c3’ without problems. (I specifically checked the last four to see if they were processed correctly. They appear to have been. You can delete that line.)
My revised code —
load('matlab') % Information (Delete Later)
whos('-file', 'matlab') % Information (Delete Later)
Name Size Bytes Class Attributes
c3 1x245 20809949 cell
fields = {'Centroid', 'Eccentricity', 'EquivDiameter'};
% files = dir('*.mat');
% NrFiles = numel(files);
for k = 1:numel(c3)
LD = c3{k};
select = {LD.Centroid; LD.Eccentricity; LD.EquivDiameter};
MeasTable = cell2table(select.', 'VariableNames',fields);
VN = MeasTable.Properties.VariableNames;
ColNrs = find(ismember(VN,fields));
ForFile{k,:} = MeasTable(:,ColNrs);
end
fprintf('\nRead and collected %d elements of ‘c3’\n', k)
Read and collected 245 elements of ‘c3’
ForFile{end-4:end} % Information (Delete Later)
ans = 2x3 table
Centroid Eccentricity EquivDiameter
________________ ____________ _____________
344.01 986.29 0.93342 39.153
345.73 870.05 0.72502 28.322
ans = 2x3 table
Centroid Eccentricity EquivDiameter
________________ ____________ _____________
343.98 989.42 0.9338 39.413
345.66 873.01 0.69685 28.028
ans = 2x3 table
Centroid Eccentricity EquivDiameter
________________ ____________ _____________
343.98 992.56 0.93325 39.606
345.6 876.28 0.68287 28.3
ans = 1x3 table
Centroid Eccentricity EquivDiameter
________________ ____________ _____________
345.42 879.79 0.61662 28.412
ans = 1x3 table
Centroid Eccentricity EquivDiameter
________________ ____________ _____________
345.49 883.11 0.52828 28.3
Combined = vertcat(ForFile{:})
Combined = 1157x3 table
Centroid Eccentricity EquivDiameter
________________ ____________ _____________
345.92 846.33 0.51444 27.915
345.02 1008.9 0.36766 26.318
345.78 875.08 0.47321 23.963
346.06 927.47 0.50862 26.845
345.5 753.92 0.65757 26.535
344.29 778.5 0.10048 8.444
345.83 850.03 0.50788 27.663
345.52 756.75 0.58771 26.678
345.79 878.01 0.46224 23.963
346.13 930.74 0.5168 26.798
344.25 782 0.34512 8.5191
345.89 853.75 0.47479 27.315
345.52 759.75 0.54122 26.726
345.75 881.11 0.41682 23.857
346.08 934.06 0.52776 26.916
344.07 785.51 0.20784 8.3683
writetable(Combined,'Combined.txt');
Check = readtable('Combined.txt') % Check Result
Check = 1157x4 table
Centroid_1 Centroid_2 Eccentricity EquivDiameter
__________ __________ ____________ _____________
345.92 846.33 0.51444 27.915
345.02 1008.9 0.36766 26.318
345.78 875.08 0.47321 23.963
346.06 927.47 0.50862 26.845
345.5 753.92 0.65757 26.535
344.29 778.5 0.10048 8.444
345.83 850.03 0.50788 27.663
345.52 756.75 0.58771 26.678
345.79 878.01 0.46224 23.963
346.13 930.74 0.5168 26.798
344.25 782 0.34512 8.5191
345.89 853.75 0.47479 27.315
345.52 759.75 0.54122 26.726
345.75 881.11 0.41682 23.857
346.08 934.06 0.52776 26.916
344.07 785.51 0.20784 8.3683
My apololgies for the delay. I had major computer problems last night with something Micro$oft did that really screwed up my computer. It took a bit over four hours, several uninstalls/reinstalls of some of the apps I need (and whose installations Micro$oft screwed up) and at least 20 warm reboots to get it back to the way I want it. I absolutely hate Windows. It used to be a decent operating system. Now, it’s just unstable crap and loaded with bloatware.
.
Turbulence Analysis
on 5 May 2024
No worries at all. Thank you very much for your kind support despite the problem you had with your computer.
I undertand the pain with the Microsoft. I had the similar issue last week, all of sudden it stopped working and end with blue screen error. I somehow rectified it. Yeah,these days, particularly working with Windows 11 is a real pain. Too many auto updates and some apps always need frequent restart for proper fucntioning.
Turbulence Analysis
on 6 May 2024
Hello again,
In the attached c3 file some columns got 0x1 struct files.
First I need to know idx of those columns and delete those columns from the c3 file before creating table.
Could you please help. I can create a seperate thred if you prefer!
Star Strider
on 6 May 2024
We just need to test for empty cells and not consider those.
Added that. The rest of my previous code is unchanged.
My revised code —
load('matlab') % Information (Delete Later)
whos('-file', 'matlab') % Information (Delete Later)
Name Size Bytes Class Attributes
c3 1x100 2409977 cell
fields = {'Centroid', 'Eccentricity', 'EquivDiameter'};
% files = dir('*.mat');
% NrFiles = numel(files);
for k = 1:numel(c3)
LD = c3{k};
SzLD = size(LD) % Information (Delete Later)
if ~isempty(LD)
select = {LD.Centroid; LD.Eccentricity; LD.EquivDiameter};
MeasTable = cell2table(select.', 'VariableNames',fields);
VN = MeasTable.Properties.VariableNames;
ColNrs = find(ismember(VN,fields));
ForFile{k,:} = MeasTable(:,ColNrs);
end
end
SzLD = 1x2
5 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
4 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
4 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
3 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
5 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
4 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
5 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
4 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
3 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
0 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
0 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
0 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
0 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
3 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
0 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
0 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
0 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
0 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
0 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
0 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
0 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
0 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
0 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
0 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
0 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
0 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SzLD = 1x2
0 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
fprintf('\nRead and collected %d elements of ‘c3’\n', k)
Read and collected 100 elements of ‘c3’
% ForFile{end-4:end} % Information (Delete Later)
Combined = vertcat(ForFile{:})
Combined = 152x3 table
Centroid Eccentricity EquivDiameter
________________ ____________ _____________
324.19 869.78 0.54943 25.382
323.5 956.85 0.53722 23.534
323.37 988.12 0.59806 23.48
324.09 915.21 0.69311 7.7358
324.22 1018.5 0.2681 8.3683
324.5 874.3 0.58058 25.054
323.6 961.95 0.225 23.723
323.33 992.42 0.61297 23.75
323.96 920.67 0.49505 7.8987
324.56 878.72 0.55415 24.437
323.66 967.22 0.4225 23.857
323.42 996.59 0.63476 23.99
324.07 925.53 0.49865 8.5191
324.44 882.9 0.44595 24.541
323.76 987.07 0.93823 34.281
323.82 929.93 0.46072 7.5694
writetable(Combined,'Combined.txt');
Check = readtable('Combined.txt') % Check Result
Check = 152x4 table
Centroid_1 Centroid_2 Eccentricity EquivDiameter
__________ __________ ____________ _____________
324.19 869.78 0.54943 25.382
323.5 956.85 0.53722 23.534
323.37 988.12 0.59806 23.48
324.09 915.21 0.69311 7.7358
324.22 1018.5 0.2681 8.3683
324.5 874.3 0.58058 25.054
323.6 961.95 0.225 23.723
323.33 992.42 0.61297 23.75
323.96 920.67 0.49505 7.8987
324.56 878.72 0.55415 24.437
323.66 967.22 0.4225 23.857
323.42 996.59 0.63476 23.99
324.07 925.53 0.49865 8.5191
324.44 882.9 0.44595 24.541
323.76 987.07 0.93823 34.281
323.82 929.93 0.46072 7.5694
.
Turbulence Analysis
on 6 May 2024
Perfect! Thanks very much.
Just crusious to know how to extract only the indices of the column of c3 which got 0 x 1 struct similar to one we do for removing NaN in normal arrays
index_nan = find(isnan(A);
Star Strider
on 6 May 2024
I did not look closely, however I do not beleive there is anything at all in the empty structures. The fields are all there, however there is nothing in any of them. There is a difference between ‘empty’ (generally although not always denoted by empty square brackets []) and ‘missing’ or NaN values. They are two different conditions, with NaN values being just that — not a number or not a time (NaT) and therefore not ‘empty’ — and empty elements that are only allowed in structures and cell arrays, and not in others, such as numeric arrays or table arrays. The ‘empty’ and NaN/NaT conditions are not equivalent.
More Answers (0)
See Also
Categories
Find more on Cell Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)