Find NaN values in cell array that stores changing types of elements over time

1 次查看(过去 30 天)
I have a 1x2 cell array (paths_upd) that stores the output of dijkstra's algorithm for two different cases. A single output(paths_upd{n} is usually also a cell array with vectors stored inside.
These vectors represent paths in a network between nodes (source nodes and target nodes; similar to an adjaceny matrix). Whenever there is no connection between 2 nodes NaN will be returned instead.
An example for paths_upd{n}:
>> paths_upd{1}
ans =
2×4 cell array
{1×2 double} {1×3 double} {1×3 double} {1×4 double}
{1×3 double} {1×2 double} {1×3 double} {1×2 double}
I want to identify any target nodes that are entirely disconnected. If in the column of a target node only NaN entries exist, there is no connection to that target node from any of the source nodes.
I have successfully used the following code to identify these target nodes:
f=target_nodes(sum(cell2mat(cellfun(@(x) any(~isnan(x)),paths_upd{1},'UniformOutput',false)),1)==0);
For the case that only one source node and one target node exist and they are disconnected the function will return NaN (double) instead of a cell array. In this case I get the following error message:
Input #2 expected to be a cell array, was double instead.
How do I best proceed to identify the disconnected target nodes for both case?
  2 个评论
dpb
dpb 2018-7-21
Show the code that generates the result to be tested; probably the way to solve the problem is to ensure it always returns the same type; perhaps you'll have to special-case it there.
I'd choose to do it at that point rather than make the fixup here, later...

请先登录,再进行评论。

采纳的回答

dpb
dpb 2018-7-21
I'd still fix it there...the very last thing in the function
function [costs,paths] = dijkstra(AorV,xyCorE,SID,FID,showWaitbar)
...
is--
% Pass the path as an array if only one source/destination were given
if L == 1 && M == 1
paths = paths{1};
end
I'd simply comment that out and all should be well and the outputs will be consistent data types for all conditions thus maintaining symmetry.
I see nothing that would prevent you from doing this that would violate any conditions placed on the code by the author; the submission seems silent on the point.
  2 个评论
dpb
dpb 2018-7-22
Indeed, why the author chose to do that and break symmetry is bad design choice imo...I complain to TMW a lot about their penchant to do similar things in and between related functions! :)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dijkstra algorithm 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by