Error using horzcat:: Dimensions of array being concentenated are not consistent

1 次查看(过去 30 天)
Hi all,
I am running the following but I got that error Dimensions of arrays being concatenated are not consistent.
clearvars;
clc;
S=[.2046e17 .1381e17 .9249e17;.1679e17 .2385e17 1.2332e17;-2.5339 2.5339 2.7582;2.5339 -2.5339 2.75]
m_idx = [min(S(S>0)), find(S==min(S(S>0)))]
I only need min value and index of such value (can I have the first lowest possible value with it's index ??
Any help

回答(2 个)

Image Analyst
Image Analyst 2021-3-21
This is a FAQ, so please read the FAQ document. It will tell you in more detail everything we'd tell you.

Stephan
Stephan 2021-3-21
编辑:Stephan 2021-3-21
There are 2 times the same values at different indices. To get only the first occourence:
S=[.2046e17 .1381e17 .9249e17;.1679e17 .2385e17 1.2332e17;-2.5339 2.5339 2.7582;2.5339 -2.5339 2.75]
m_idx = [min(S(S>0)), find(S==min(S(S>0)),1)]
or like i commented in your question before use a function to get all indices where the positive minimum value occours:
S=[.2046e17 .1381e17 .9249e17;.1679e17 .2385e17 1.2332e17;-2.5339 2.5339 2.7582;2.5339 -2.5339 2.75]
[m, idx] = myFun(S)
function [m, idx] = myFun(S)
m = min(S(S>0));
idx = find(S==min(S(S>0)));
end

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by