How do i label values in a mat file and save it in another mat file in matlab?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a mat file of 732 x 1 DOUBLE named as EnginePower. I used the mean function to find the average value of my engine power, i would first like to compare all the values against my mean value and those that are lower than the mean i would like to label it as -1 and those higher than mean as 1 in another new mat file. I'm wondering if this is possible ?
0 commentaires
Réponse acceptée
Image Analyst
le 28 Jan 2015
Try this:
storedStructure = load(inputFileName);
EnginePower = storedStructure.EnginePower;
meanValue = mean(EnginePower);
logicalIndex = EnginePower > meanValue; % Find elements > mean
% Create a new output matrix
output = logicalIndex; % Initialize - now it's 0 and 1.
% Now set 0's to -1
output(logicalIndex) = -1;
% Write out
save(outputFileName, 'output');
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Operators and Elementary Operations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!