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?

Answers (1)

You can initialize with

W = zeros(size(DF));

or with

 W = 0 * DF;

9 Comments

can i do it like this pr_size = size (DF, W) ? is it tell the same thing? because the pr_size i will be using for another thing at another part of the code
No, but you can code
W = zeros(pr_size, size(DF,2))
may i know, what is "zeros" mean ?
if i put the code like this
% PROBLEM SIZE (NUMBER OF SITES OR DEPTS)
W = zeros(pr_size, size(DF,2))
the will be an error said that "Undefined function or variable 'pr_size'."
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()
thank you so much for the info..
if i put the code like this
% PROBLEM SIZE (NUMBER OF SITES OR DEPTS)
W = zeros(pr_size, size(DF,2))
the will be an error said that "Undefined function or variable 'pr_size'."
if i put it like this
% PROBLEM SIZE (NUMBER OF SITES OR DEPTS)
pr_size = size(DF,1);
W = ones(pr_size, size(DF,2));
will matlab rewrite one of them?
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?
i already have DF and W matrix, they are the same, i want to add matrix DF with W,

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!