日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人工智能 > 循环神经网络 >内容正文

循环神经网络

matlab循环矢量化 嵌套,在Matlab中对for循环进行矢量化,得到不同结果的看似等效的代码...

發布時間:2024/1/23 循环神经网络 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 matlab循环矢量化 嵌套,在Matlab中对for循环进行矢量化,得到不同结果的看似等效的代码... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我正在嘗試引導我正在處理的一段代碼,但是我收到了奇怪的結果,這些結果不會發生在看起來相同的for-loop中。任何人都可以看到為什么這兩個版本獲得不同的結果?

此外,如果任何人有任何指示我如何能夠引導第一個for循環,并為每個單元格生成一個二進制位置矩陣,那將是甜蜜的。

非常感謝您的幫助

Formatted code

普通代碼:

function create_distances()

x=3; % Dimensions of grid

y=3;

num_cells=x*y; % Num of cells in grid

% In following code a matrix is generated for each cell, in which that cell

% is set to 1 and all others zero.

locations=zeros(x,y,num_cells); % Initialise blank array to store each location on grid

for current_index=1:num_cells;

temp=locations(:,:,current_index);

temp([current_index])=1;% Set a single cell to 1 to represent which cell is the active one for each of the cells

locations(:,:,current_index)=temp; % Store back to that location matrix

end

%%For loop version which correctly creates the distances

distances_from_position1=zeros(x,y,num_cells);

for current_location1=1:num_cells

distances_from_position1(:,:,current_location1)=bwdist(locations(:,:,current_location1));

end

% Vectorised version of same code which gives incorrect distance values

current_location2=1:num_cells;

distances_from_position2=zeros(x,y,num_cells);

distances_from_position2(:,:,current_location2)=bwdist(locations(:,:,current_location2));

%Gives correct results

correct_values=distances_from_position1

%incorrect_values=distances_from_position2;

if eq(distances_from_position1,distances_from_position2)==1

disp('Same results')

else

disp('Two methods give different results') %This message shown each time

end

總結

以上是生活随笔為你收集整理的matlab循环矢量化 嵌套,在Matlab中对for循环进行矢量化,得到不同结果的看似等效的代码...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。