How do i code this variable in Matlab
显示 更早的评论
i have 2 matrix which have have same size.. if 1st matrix is size 5 the 2nd will also will be 5 if the 1st matrix is size 10 the 2nd will be 10
for example
%1st matrix
DF = [NaN 4 6 ;
3 NaN 5 ;
5 4 NaN ] ;
%2nd matrix
W = [6 10 5 ;
9 7 3 ;
1 4 8 ];
% PROBLEM SIZE (NUMBER OF SITES OR DEPTS)
pr_size = size(DF,1);
how do i code matrix W as pr_size? because W will be follow DF size?
回答(1 个)
Walter Roberson
2018-4-17
You can initialize with
W = zeros(size(DF));
or with
W = 0 * DF;
9 个评论
sharifah shuthairah syed abdullah
2018-4-17
Walter Roberson
2018-4-17
No, but you can code
W = zeros(pr_size, size(DF,2))
sharifah shuthairah syed abdullah
2018-4-17
sharifah shuthairah syed abdullah
2018-4-17
编辑:sharifah shuthairah syed abdullah
2018-4-17
Walter Roberson
2018-4-17
zeros() is allocates an array of the given size, all filled with the value 0.
There is also a function ones() that allocates a matrix of the given size, all filled with the value 1.
You can also use size arguments for nan() and for inf() and for true() and false()
sharifah shuthairah syed abdullah
2018-4-17
编辑:Walter Roberson
2018-4-17
Walter Roberson
2018-4-17
You need to define pr_size before you can use it.
I do not understand what you mean about writing one of them?
Is it possible that you already have D and already have W, and the task is to check to see whether they do have the same size or not?
sharifah shuthairah syed abdullah
2018-4-17
Walter Roberson
2018-4-17
DF + W
类别
在 帮助中心 和 File Exchange 中查找有关 NaNs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!