(subjectively) IMPORTANT QUESTION! Please help.
Show older comments
Hi,
I am creating a .m file and a GUI for quality assurance purposes to inspect segmented ROIs previously worked on by a student. The data is of mice and is organized by weeks. For example, Week 0 would have 9 mice associated with that data set. The workflow that I made (although I am sure it will be criticized) is to load the experimental mice data into a struct into MATLAB. This is done per week. So what I'd ideally like to have is 4 structs (W0, W4, W8, W20). I would like to then save this struct so that I can use it at a later date. Because the entire process takes quite some time (~8 minutes per mouse, with 9 mice per week), I think this would be helpful. The problem that I am having is that, I receive an "OUT OF MEMORY" error from MATLAB after going through 3 mice. As you can tell, this destroys my aforementioned workflow since I'd like to save an entire struct containing specifically chosen data for all mice imaged at a certain week.
The "quality assurance" is accomplished through my creation of a GUI that enables the plotting of the data from the 3 acquired positions per mouse, per frame, per week for easy inspection of the segmented ROIs.
I am currently running a main script that: 1. Loads into MATLAB multiple single files that contains experimental data from individual mice (each file corresponding to a single mouse). 2. Then, I create a struct in MATLAB that first contains fields with the names of the corresponding mice and other respective data. 3. Then, I create more structs inside this struct the data that I need to pass into the struct. The over-arching struct used is called 'mouseinfo'. 4. Then, I pass 'mouseinfo' into my GUI and everything else works wonderfully. The issue lies in Step 3. with passing all the experimental mouse data into the struct.
See this major snippet of my main code:
%
mouseinfo(1).cage = 'B140308';
% mouseinfo(2).cage = 'B140536';
% mouseinfo(3).cage = 'B140874';
% mouseinfo(4).cage = 'LL140536';
% mouseinfo(5).cage = 'R140308';
% mouseinfo(6).cage = 'R140536';
% mouseinfo(7).cage = 'R140874';
% mouseinfo(8).cage = 'RR140536';
% mouseinfo(9).cage = 'RR140874';
for n = 1%9
mouseinfo(n).week = 0;
mouseinfo(n).cage_nr = 1;
ii = 1;
col = 'rgb';
for pos = 0:2
Output_fname = strcat('Outputs_', mouseinfo(n).cage,'_W', num2str(mouseinfo(n).week), '_left_spectro', num2str(pos));
OP = load([Output_fname, '.mat']);
OP = OP.(Output_fname);
mouseinfo(n).pos(pos+1).ROI_mask = OP.ROI_mask;
mouseinfo(n).pos(pos+1).ROI_xi = OP.xi;
mouseinfo(n).pos(pos+1).ROI_yi = OP.yi;
mouseinfo(n).pos(pos+1).PA_avg = OP.PA_avg;
mouseinfo(n).pos(pos+1).US_avg = OP.US_avg;
mouseinfo(n).pos(pos+1).PA_fit = OP.PA_fit;
mouseinfo(n).pos(pos+1).US_fit = OP.US_fit;
mouseinfo(n).pos(pos+1).PA_slope = OP.PA_slope;
mouseinfo(n).pos(pos+1).US_slope = OP.US_slope;
jj = 1;
for frame = 1:59
clear PA_fname
frame
ENW = xlsread(strcat(mouseinfo(n).cage,'_W', num2str(mouseinfo(n).week), '_left_spectro', num2str(pos), '_PAMODE.csv'));
mouseinfo(n).pos(pos+1).frame(frame).ene = mean(ENW(frame+7, 8:11));
% Load PA data
PA_fname = strcat('PA_', mouseinfo(n).cage,'_W', num2str(mouseinfo(n).week), '_left_spectro', num2str(pos), '_fr_', num2str(frame));
PA = load([PA_fname, '.mat']);
PA = PA.(PA_fname);
mouseinfo(n).pos(pos+1).frame(frame).PA = real(PA)./mouseinfo(n).pos(pos+1).frame(frame).ene;
[pa_row, pa_col] = size(mouseinfo(n).pos(pos+1).frame(frame).PA);
[mouseinfo(n).pos(pos+1).frame(frame).PA_SA, mouseinfo(n).pos(pos+1).frame(frame).PA_LCI] = compute_SA_LCI(mouseinfo(n).pos(pos+1).frame(frame).PA);
% Load US data
US_fname = char(strcat(mouseinfo(n).cage,'_W', num2str(mouseinfo(n).week), '_left_spectro', num2str(pos), '.iq'));
[mouseinfo(n).pos(pos+1).frame(frame).US, mouseinfo(n).pos(pos+1).frame(frame).LatD, mouseinfo(n).pos(pos+1).frame(frame).AxD] = US_VevoLAZR_ReconstructRF(US_fname, 1, box_start, box_end, box_width, pa_row, pa_col);
[mouseinfo(n).pos(pos+1).frame(frame).US_SA, mouseinfo(n).pos(pos+1).frame(frame).US_LCI] = compute_SA_LCI(mouseinfo(n).pos(pos+1).frame(frame).US);
mouseinfo(n).pos(pos+1).frame(frame).PA2 = (mouseinfo(n).pos(pos+1).frame(frame).PA) .* (mouseinfo(n).pos(pos+1).ROI_mask);
[mouseinfo(n).pos(pos+1).frame(frame).PA2_SA, mouseinfo(n).pos(pos+1).frame(frame).PA2_LCI] = compute_SA_LCI(mouseinfo(n).pos(pos+1).frame(frame).PA2);
mouseinfo(n).pos(pos+1).frame(frame).PA2_SA_avg= nanmean(mouseinfo(n).pos(pos+1).frame(frame).PA2_SA(:));
%
mouseinfo(n).pos(pos+1).frame(frame).PA2 = remove_nan(mouseinfo(n).pos(pos+1).frame(frame).PA2);
[pa_row1, pa_col1] = size(mouseinfo(n).pos(pos+1).frame(frame).PA2);
% FFT
[pa_freq, mouseinfo(n).pos(pos+1).frame(frame).PA_PS] = sig_fft(mouseinfo(n).pos(pos+1).frame(frame).PA2, pa_fs, 2);
mouseinfo(n).pos(pos+1).frame(frame).PA_PS_avg = nanmean(mouseinfo(n).pos(pos+1).frame(frame).PA_PS, 2);
mouseinfo(n).pos(pos+1).frame(frame).PA_PS_fr = mouseinfo(n).pos(pos+1).frame(frame).PA_PS_avg;
[freq_ind, mouseinfo(n).pos(pos+1).frame(frame).ISP] = int_spec_pow(pa_freq, mouseinfo(n).pos(pos+1).frame(frame).PA_PS_avg);
end
clear Output_fname
clear OP
end
end
Once again, my issue is that I receive an "Out of Memory" error from MATLAB after 3 mice after loading in specific data into the struct 'mouseinfo'. Any help is appreciated! I'd love to have this solved ASAP.
2 Comments
Walter Roberson
on 10 Oct 2018
Now, although it is true that I have been known to post unimportant questions, because I am a curious completist, it seems to me that most people who post here consider their questions to be "important", at least to them.
Accepted Answer
More Answers (0)
Categories
Find more on Read, Write, and Modify Image 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!