フィルターのクリア

discrte to softmax : Attempt to grow array along ambiguous dimension

1 回表示 (過去 30 日間)
Tomasz Kaczmarski
Tomasz Kaczmarski 2020 年 2 月 18 日
編集済み: Tomasz Kaczmarski 2020 年 2 月 21 日
Hello
Im trying to run below function but constantly getting error
Attempt to grow array along ambiguous dimension.
Error in discrete2softmax (line 5)
s_m([1:sNum] + (inp'-1)*sNum) = 1;%problem
I know its caused becouse target is larger then array but please help how i should change my code to make it work
function s_m = discrete2softmax(inp,nmax)
% Convert discrete data into softmax
sNum = size(inp,1);
s_m = zeros(sNum,nmax);
s_m([1:sNum] + (inp'-1)*sNum) = 1;%problem
end
  4 件のコメント
Walter Roberson
Walter Roberson 2020 年 2 月 20 日
Change the [] to ()
Tomasz Kaczmarski
Tomasz Kaczmarski 2020 年 2 月 21 日
編集済み: Tomasz Kaczmarski 2020 年 2 月 21 日
thanks changing brackets improved code but i still got error
after more debbugging i think i know where my problem is
if s_m got mix of 0 and 1 it work well if i load 0 ( as on screen) only it fails
how to change function to move forward without failing if s_m got zeros only

サインインしてコメントする。

採用された回答

Matt J
Matt J 2020 年 2 月 19 日
編集済み: Matt J 2020 年 2 月 19 日
I know its caused becouse target is larger then array but please help how i should change my code to make it work
Did you intend to add data at locations outside the bounds of s_m? If so, you would have to do so with 2D subscript indexing, rather than with a 1D linear index, e.g.,
>> s_m=rand(2)
s_m =
0.7088 0.9239
0.1146 0.7881
>> s_m(3,4)=1
s_m =
0.7088 0.9239 0 0
0.1146 0.7881 0 0
0 0 0 1.0000

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by