matlab - MATLAB:用 NaN 替换元胞数组中的列
问题描述
我有一个 3x2 单元格数组data
,其中每个单元格都包含一个双矩阵。它看起来像这样:
{600x4 double} {600x4x3 double}
{600x4 double} {600x4x3 double}
{600x4 double} {600x4x3 double}
现在,我想用 NaN 替换元胞数组的第二列。因此,结果应如下所示:
{600x4 double} {[NaN]}
{600x4 double} {[NaN]}
{600x4 double} {[NaN]}
使用花括号无济于事。
data{:,2} = nan
Expected one output from a curly brace or dot indexing expression, but there were 3 results.
我想我可以使用cellfun
或一个简单的 for 循环将值更改为NaN
. 但是,我想知道是否有更简单的解决方案?
解决方案
你可以用这个
data(:,2) = {NaN};
逻辑:
% Assign all values in the 2nd column of the cell ...
% All elements should be the single cell {NaN};
您也可以这样做(逻辑更清晰)
data(:,2) = repmat( {NaN}, size(data,1), 1 ); % Right hand side is same height as data
甚至这个!
data(:,2) = num2cell( NaN(size(data,1), 1 ) );
推荐阅读
- java - 从应用程序发送电子邮件时出现 javax.ejb.EJBException
- spss - 使用 ROC 曲线分析 SPSS 中的数据用于分类变量(名义)
- reactjs - React Query:何时使用 useInfiniteQuery 或 usePaginatedQuery 进行分页
- flutter - 为什么每次我将 ListView 添加到我的 Column 时,所有小部件都会消失?
- swiftui - 如何防止工作表在 SwiftUI 中使其后面的视图变暗或删除不必要的填充?
- angular - 我可以重新抛出 500 的角度 http 拦截器吗?
- sql - Node.js mssql 与 SQL 服务器的多个并发连接相互干扰
- reactjs - React Native 中的重新渲染问题
- javascript - setTimeout 限制 http 请求
- python - 从字典和列表生成字典