简体   繁体   English

如何在Matlab中使用变量创建矩阵?

[英]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. 我有四个使用NetCDF数据创建的变量,分别是高度,纬度,经度和日期。 Now I want to create a single matrix with these variables as a column then I supposed to neglect values containing "NAN" data. 现在,我想用这些变量作为一个列来创建一个矩阵,然后忽略包含“ NAN”数据的值。

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. 的数据是579X1所有变量,但是当我从Height中删除Nan值时,其尺寸减小为45X1现在,我要尝试的是减小所有变量的尺寸wrt Height。

I have got my matrix, now wanted to remove all rows containing Nan Value 我有我的矩阵,现在想删除所有包含Nan Value的行

NaN 736536.710457717 28.3771283105297 69.6958150783291 NaN 736536.710457858 28.3778490697636 69.6956231314990 NaN 736536.710457717 28.3771283105297 69.6958150783291 NaN 736536.710457717 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 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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