简体   繁体   中英

How to create a matrix in matlab using variables?

I have four variables which I created using NetCDF data namely height, lat, long and date. Now I want to create a single matrix with these variables as a column then I supposed to neglect values containing "NAN" data.

I have done this separately, but I want in a single matrix. I have to run this process on multiple files.

for i = 1:length(theFiles)% Loop for each nc-file
    %Select Single cycle
    FileName = theFiles(i).name; 

    FullPathName=fullfile(folder_name, FileName); %reading file one by one
    disp(['File selected:', FullPathName])


    [Height,time,Lat,Long]=read_netcdf(FullPathName);  % Read the selected nc file 
     lattiude=Lat;
     longitude=Long;

     B = [Height,time,Lat,Long];   
    end 

One more thing, total no. of data is 579X1 all variable but as I remove Nan value from Height, its dimension reduces to 45X1 Now what I am trying to do is to reduce all the variables dimensions wrt Height.

I have got my matrix, now wanted to remove all rows containing Nan Value

NaN 736536.710457717 28.3771283105297 69.6958150783291 NaN 736536.710457858 28.3778490697636 69.6956231314990
75 736536.710458284 28.3800119048871 69.6950471308031 75 736536.710458426 28.3807327583405 69.6948551510433 NaN 736536.710458000 28.3785699096006 69.6954311612445 NaN 736536.710458142 28.3792909110158 69.6952391459993

Not sure if this is what you are asking, but you can increase the size of arrays like this:

for i = 1:n
   B = [B; newValue];
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM