How can I know if my laptop is plugged into AC power via Matlab?
조회 수: 8 (최근 30일)
이전 댓글 표시
Hello,
is there a way to know through Matlab if the laptop is currently plugged in AC power or running on battery?
Thanks,
Mark
댓글 수: 0
채택된 답변
Les Beckham
2019년 12월 15일
편집: Les Beckham
2019년 12월 15일
That error message (''pmset' is not recognized as an internal or external command, operable program or batch file) is a Windows error message.
Based on this blog post you can determine this in Windows using an undocumented/unsupported class in Powershell:
Put this Powershell script wherever you wish (like in your "Documents" folder, for instance):
Function Test-IsOnBattery
{
Param(
[string]$computer
)
if ([BOOL](Get-WmiObject -Class BatteryStatus -Namespace root\wmi -ComputerName $computer).PowerOnLine)
{Write-Output "On AC Power"}
else
{Write-Output "On Battery"}
} #end function test-IsOnBattery
Test-IsOnBattery -computer <YourComputerName>
Name the file Test-IsOnBattery.ps1.
Then call it from Matlab like this:
[status, output] = system("powershell C:/Users/<YourUserName>/Documents/Test-IsOnBattery");
Then you can test the result like this:
if strfind(output, "AC")
disp('AC')
else
disp('Battery')
end
I hope this helps.
댓글 수: 7
Les Beckham
2019년 12월 29일
Yes. Quite unfortunate, as I found this question quite interesting to investigate and experiment with. Happy holidays to you and yours, Walter.
추가 답변 (1개)
Walter Roberson
2019년 12월 15일
편집: Walter Roberson
2019년 12월 15일
You can adapt that in MATLAB by using system() of the pmset piped to head, and receive the result as the second output of system, and do the string testing in MATLAB.
댓글 수: 4
Walter Roberson
2019년 12월 15일
That is very odd. The only way I can think of that that could happen is is if you installed something like Parallels in compatibility mode and then accidentally linked /bin/bash to /Applications/Parallels13.02.app/contents/bin/command.exe -- but if you had done that I would tend to doubt that you would have been able to boot all the way.
Hmmm... No, even if you were using R2012a with OS 10.15 that error message does not make any sense, too many other things would have to have gone wrong.
Is your laptop "Late 2012" or would it happen to be "Mid 2012" or earlier? MATLAB does happen to be compatible with selected Mid 2012 models but not Early 2012 models (not if you are using R2019b and OS 10.15); I ask because we just might need to guide you through using the Recovery Partition to fix /bin/bash but the mid 2012 models did not yet have Recovery Partition and have to be recovered from DVD.
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!