フィルターのクリア

Converting a Python code that deals with arrays to MATLAB

4 ビュー (過去 30 日間)
Anas Wheba
Anas Wheba 2022 年 1 月 6 日
回答済み: Vandit 2023 年 6 月 27 日
Hello Everyone,
I'M working on a spike sotring code in python but When I tried to convert it to MATLAB, the code did not work as expected. please can anyone help me to solve my issue ?
Python Code:
if np.max(tmpW) < max_thresh:
tmpS = np.argmax(tmpW) +i
tmpW = data[tmpS-(sw-offset):tmpS+(sw+offset)]
ss = np.append(ss, tmpS)
wf = np.append(wf, tmpW.reshape(1, sw*2), axis=0)
# Remove duplicates
ind = np.where(np.diff(ss) > 1)[0]
ss = ss[ind]
wf = wf[ind]
Matlab code:
if max(wave_form1)< max_thresh
tmp_samp = find(max(wave_form1))+i
wave_form1 = data(tmp_samp-(spike_window-offset):tmp_samp+(spike_window+offset))
spike_samp=[spike_samp tmp_samp]
wave_from = [wave_form wave_form1]
end
  6 件のコメント
Walter Roberson
Walter Roberson 2022 年 1 月 13 日
At the time of the error, what is size(data), and the values tmp_samp, spike_window, and offset ? Also, what are the maximum and minimum values for tmp_samp as you iterate through the loop ?
Yongjian Feng
Yongjian Feng 2022 年 1 月 21 日
Also this line is suspicious:
tmp_samp = find(max(wave_form1))+i
Do you want this instead?
tmp_samp = find(wave_form1 == max(wave_form1))+i

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

回答 (1 件)

Vandit
Vandit 2023 年 6 月 27 日
Hello,
After assuming that 'wave_form', 'wave_form1', 'spike_samp', 'wave_from', 'max_thresh', 'data, spike_window',' offset', and 'i' are defined correctly in your MATLAB environment, the issue in the MATLAB code lies in the lines:
tmp_samp = find(max(wave_form1)) + i; %Incorrect code
tmp_samp = find(wave_form1 == max(wave_form1)) + i; %Modified code
The reason for changing the above code is to find the indices of the maximum value(s) in 'wave_form1' rather than just the first occurrence. In the original Python code, 'np.argmax(tmpW)' returns the index of the first occurrence of the maximum value in 'tmpW'. However, in MATLAB, using 'find(max(wave_form1))' would only return the index of the first occurrence of the maximum value in 'wave_form1', which may not be the desired behavior.
wave_from = [wave_form wave_form1]; %Incorrect code
wave_form = [wave_form; wave_form1]; %Modified code
The reason for changing the code is to correctly append the 'wave_form1' waveform as a new row to the 'wave_form' matrix. In the original Python code, 'wf' is an array where each row represents a waveform. In the MATLAB code, the equivalent variable is 'wave_form'. To correctly append 'wave_form1' as a new row to 'wave_form', we need to use the semicolon (;) to separate the rows.
Hope this helps.
Thankyou

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by