why are the names not being saved as written? Why do i get this error each time? Also why is the legend wrong? please fix this so i can verify my code is working as intended.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hi so the second code calculates the SEM of each struct (std error of mean) and adds it to the mat file and gives you an updated mat file. But I can't change the name to what I want so I just leave it as features. for ex: features1SEM without this error:
Error using save
Variable 'features1SEM' not found.
Error in semcalculationsbetweenfields (line 20)
save('featuresLD2.mat', 'features1SEM');
The first code plots the data and the sem with the space between them shaded in to give area style fill. but i noticed that despite what i name them they are loaded differntly hence why the load file name is different than the name in the for loop. can someone explain why and confirm that the sem calculated is the sem of the structs and that its plotted correctly?Also In the legend i try to make the first 3 data sets a different color from the next 3 but the lines in the legend don't necessarily allow this or at least I am not sure how to do it. Can you please help me to also make the legend accurately reflect the data plotted? Thank you!
Plotting SEM
clear all
% Load the mat file
load('features1SEMa.mat');
load('features2SEMa.mat');
% Plot the total area for each feature in each mat file
subplot(3,3,1)
hold on;
% Plot Lobule 1-3 in blue
for i = 1:3
x = 13 - (1:length(features1SEM(i).totalArea));
y = features1SEM(i).totalArea;
SEM = features1SEM(i).totalArea_SEM;
y_upper = y + SEM;
y_lower = y - SEM;
fill([x, fliplr(x)], [y_upper, fliplr(y_lower)], 'blue', 'FaceAlpha', 0.2, 'EdgeColor', 'none');
plot(x, y, 'LineWidth', 2, 'color', 'blue');
end
% Plot Lobule 4-6 in red
for i = 1:3
x = 13 - (1:length(features(i).totalArea));
y = features(i).totalArea;
SEM = features(i).totalArea_SEM;
y_upper = y + SEM;
y_lower = y - SEM;
fill([x, fliplr(x)], [y_upper, fliplr(y_lower)], 'red', 'FaceAlpha', 0.2, 'EdgeColor', 'none');
plot(x, y, 'LineWidth', 2, 'color', 'red');
end
xlim([1, length(features1SEM(i).totalArea)]);
xticks(1:length(features1SEM(i).totalArea));
xlabel('PP - PC axis');
ylabel('Lipid Droplet Count');
legend('(\color{blue}Lobule 1-3\color{black})', '(\color{red}Lobule 4-6\color{black})');
title('Lipid Droplet Count');
Calculating SEM
clear all
% Load the mat file
load('featuresLD2.mat');
% Calculate SEM between fields for each feature
fieldnames = {'totalArea', 'AvgCircularityy', 'profileCounts', 'zoneArea', 'AvgFeret', 'avgSize'};
for j = 1:numel(fieldnames)
data = [features(1).(fieldnames{j}), features(2).(fieldnames{j}), features(3).(fieldnames{j})];
SEM = std(data) / sqrt(numel(data));
% Add SEM to the feature structure for each feature
for i = 1:3
fieldname_with_SEM = [fieldnames{j} '_SEM'];
features(i).(fieldname_with_SEM) = SEM;
end
end
% Save the updated mat file
save('featuresLD2.mat', 'features');
0 Commenti
Risposte (1)
Steven Lord
il 19 Mag 2023
Which line of code is actually part of your program? The line from the error message:
save('featuresLD2.mat', 'features1SEM');
does not appear in any of the code you posted. The closest line that does is the last line of your second file:
save('featuresLD2.mat', 'features');
You start off that second file with clear all so only the variables you load from featuresLD2.mat in that file or create inside that file exist in the workspace. Nowhere do you create or modify a variable named features1SEM, so the error message makes sense if that line from the error message is what's actually in your code (and that variable is not part of featuresLD2.mat.)
Vedere anche
Categorie
Scopri di più su Automated Fixed-Point Conversion in MATLAB in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!