How do i label values in a mat file and save it in another mat file in matlab?

조회 수: 1 (최근 30일)
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 ?

채택된 답변

Image Analyst
Image Analyst 2015년 1월 28일
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');
  댓글 수: 1
crixus
crixus 2015년 1월 29일
Thanks for your reply ! I followed your instruction and the code works ! my svm is able to run successfully ! but i have one question when i use this output(logicalIndex) = -1; how come the 0 in the output file located in my workspace does not change to -1 ??

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by