Data not saving in excel spreadsheet.

I have a series of values stored in a cell array that I am saving as an excel spreadsheet. The code to make the excel file is working except for the fact that the spreadsheet is empty when opened. I suspect that this is due to the creation of the data earlier in the code. I have used regionprops to calculate the average intensity inside two regions of interest on a number of matrices stored in a cell array. I have saved the resultant cell array, which should be composed of two columns(the ROI) and a number of rows(the matrices), but when i attempt to open it Matlab claims the directory does not exist. The code to calculate this mean intensity is set up to create this cell array of mean intensity values and I cannot tell where the problem may arise.
for i = 1 : numel(Y)
X = Y{i}.*mask;
end
for i = 1 : length(X)
thisImage = X{i}; % Extract matrix from cell array of matrices.
%Get allIGLs for that image.
props = regionprops(thisImage, 'Area', 'MeanIntensity'); %get these properties for each of the cells in the array 1 : length(i)
allAreas = [props.Area]; % the areas are stored in an array
allMeans = [props.MeanIntensity]; % the means are stored in an array
allIGLs = allAreas .* allMeans; % % The average intensity is calculated
caIGLs{i} = allIGLs; % Store IGLs for this image into a cell array called caIGLs
end
My one suspicion was that rather than save each intensity value in its own discreet cell, the intensities were added together (summed) but the code is set up to calculate the intensity from each matrix individually. This suspicion arose as upon changing xlswrite(fullfile(Folder, Name), Cell_Array, Sheet); to xlswrite(fullfile(Folder, Name), Cell_Array{:}, Sheet); when creating the excel, where Cell_Array is the file created using regionprops (caIGLs)

6 Commenti

Adam
Adam il 11 Ago 2017
Modificato: Adam il 11 Ago 2017
You seem to be mixing together a lot of bits and pieces in this question to the extent I can't really understand what you are asking. You talk about saving to a spreadsheet, but then move on to say that you earlier save a cell array which does not open because Matlab says the directory doesn't exist. This seems fairly significant, but then you just move on with some code that appears not to be related either to saving the cell array nor loading it or saving the Excel file.
It is much easier to get help if you focus in on the problem. Code to calculate 'something' has no bearing on saving to Excel unless the 'something' ends up empty, in which case the saving to Excel is not relevant. Equally, if the data that is important is in the supposedly saved cell array in the directory which doesn't exist then this seems to be the key issue.
for i = 1 : numel(Y)
X = Y{i}.*mask;
end
for i = 1 : length(X)
thisImage = X{i}; % Extract matrix from cell array of matrices.
%Get allIGLs for that image.
props = regionprops(thisImage, 'Area', 'MeanIntensity'); %get these properties for each of the cells in the array 1 : length(i)
allAreas = [props.Area]; % the areas are stored in an array
allMeans = [props.MeanIntensity]; % the means are stored in an array
allIGLs = allAreas .* allMeans; % % The average intensity is calculated
caIGLs{i} = allIGLs; % Store IGLs for this image into a cell array called caIGLs
end
Folder = 'C:\Users\c13459232\Documents\MATLAB\Completed code thus far\Results';
filename = 'testData.mat';
file = caIGLs(i);
save(fullfile(Folder, filename), 'file');
This^ is the code for calculating the mean intensity and then saving it as a .mat file
Folder = 'C:\Users\c13459232\Documents\MATLAB\Completed code thus far\Results';
Cell_Array = handles.caIGLs;
Sheet = 1;
Name = 'testdata.xlsx';
xlswrite(fullfile(Folder, Name), Cell_Array, Sheet);
This^ is the code to create the excel file.
When attempting to open the .mat file:
Folder = 'C:\Users\c13459232\Documents\MATLAB\Completed code thus far\Results';
>> File= uigetfile('C:\Users\c13459232\Documents\MATLAB\Completed code thus far\Results');
>> load(File)
Error using load
Unable to read file testData.mat: No such file or directory.
It appears that there is a problem creating the .mat file, which leads me to believe that there is a problem in calculating the mean intensities for the matrices in the cell array
Adam
Adam il 11 Ago 2017
Well the first obvious question is 'Does the mat file actually exist after you have saved it?'.
I don't really see how an error saying a directory doesn't exist could be in any way related to the calculation of the data that you supposedly saved there though.
Using the debugger will quickly tell you whether the data you have at the point you call save is sensible or not. Looking in Windows explorer will quickly tell you if the mat file was saved correctly or not. If the answer to both of these is yes then the problem comes somewhere between saving and trying to load the data again.
From looking at it in the command window, my suspicion was correct. Rather than getting the mean and the area for the regions of interest for each cell and keeping them as individual cells, the code gets the mean for all the cells for both regions of interest and sums them together so that when I calculate the mean intensity there is only one value for each region of interest rather than 130 values (the number of cells in the cell array)
Aaron Smith
Aaron Smith il 14 Ago 2017
Modificato: Aaron Smith il 14 Ago 2017
I have tried everything I can think of like specifying that the inputs are cell arrays as is shown in this Mathworks thread : Here
In every other loop for loop i've ever used, by specifying the number of files in the cell array it determines how many iterations are to be done. It appears that all of the iterations are being done but instead of saving the data in a cell array it is getting the sum of all 130 cells leaving only one cell for area and one cell per region for area, one cell per region for mean and when they are multiplied by each other, it again only has one cell for each region.
Adam
Adam il 14 Ago 2017
You should probably change the title of the question if it is actually about regionprops and nothing to do with the Excel saving. It might get more attention from people who know about using regionprops.

Accedi per commentare.

Risposte (0)

Prodotti

Richiesto:

il 11 Ago 2017

Commentato:

il 14 Ago 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by