Problem using max function on relatively large arrays
1 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I'm trying to find maximum and minimum value of my vector: power_laboratori (82218 x 1, double), but when I apply both max ad min functions MATLAB gives me as a result a matrix 82218 x 7, containing more ore less the same values I had in my original vector.
the code I used is extremely simple:
Max= max(power_laboratori, 'omitnan');
can someone explain what's happening or what I'm missing?
thank you in advance
1 个评论
Stephen23
2018-5-23
编辑:Stephen23
2018-5-23
@Giulia Buraglio: The max syntax that you are using does not do what you think it does: the second argument is interpreted as a seven element vector double('omitnan'). According to the max documentation you should use:
max(power_laboratori, [], 'omitnan')
Read this for an explanation of why the [] argument is required:
回答(1 个)
Guillaume
2018-5-23
编辑:Guillaume
2018-5-23
The proper syntax is:
max(power_laboratori, [], 'omitnan')
The [] is important as 'omitnan' must be the third argument, not the second. At the moment because of implicit expansion you're calculating the maximum of each element of your matrix with the characters of 'omitnan' replicated along the rows. In effect,
Max = [max(pl(1), 'o'), max(pl(1), 'm'), max(pl(1), 'i'), ..., max(pl(1), 't');
max(pl(2), 'o'), max(pl(2), 'm'), max(pl(2), 'i'), ..., max(pl(2), 't');
...
max(pl(82218), 'o'), max(pl(82218), 'm'), max(pl(82218), 'i'), ..., max(pl(82218), 't')]
is what you were calculated (where pl stands for power_laboratori)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!