我有一个3x2的单元格数组const required = value => (value ? undefined : 'Required');
render() {
return (
<form onSubmit={handleSubmit(this.submit)}>
<div id="authId-searchbar">
<Field
component="TextField"
type="text"
name="authId"
placeholder="Enter an auth-Id..."
validate={required}
/>
</div>
<Field
component="Dropdown"
header="Choose a credential type"
name="type"
items={[
{ value: "product a", id: 1 },
{ value: "product b", id: 2 }
]}
validate={required}
/>
<button
type="submit"
disabled={pristine || submitting}
>
<SaveIcon />
</button>
</form>
);
}
,其中每个单元格都包含一个双矩阵。看起来像这样:
data
现在,我想用NaN替换单元格数组的第二列。因此,结果应如下所示:
{600x4 double} {600x4x3 double}
{600x4 double} {600x4x3 double}
{600x4 double} {600x4x3 double}
使用花括号无济于事。
{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.
或简单的for循环将值更改为cellfun
。但是,我想知道是否有更简单的解决方案?
答案 0 :(得分:3)
您可以使用此
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 ) );