Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
creating large array with sporadic nonzero elements

Subject: creating large array with sporadic nonzero elements

From: Jonathan W Smith

Date: 7 Jan, 2011 00:58:04

Message: 1 of 1

Hello

My goal is to output 1000 166x333 arrays that contain mostly zeros, but have sporadic nonzero elements. Below you will see the variable "ind_keep" which is based whether or not a particular latitude or longitude meets a logical constraint. If it does I want that count that row or those rows of lat size(lat(ind_keep)). The row of this number "val" should be printed to the corresponding element of one of the 1000 arrays. I have been getting arrays with all zero elements and no arrays with sporadic nonzero elements. Any suggestions would be great. Thanks

xlon = load('xlong_u.txt')
           xlat = load('xlat_v.txt')
                        for fnames = dir('C:\Documents and Settings\Administrator\
                                             Desktop\work\hourly_wwlln_lightning_text\wwlln*')
    
                            numfids = length(fnames)
                            vals = cell(1,numfids)
                                for M = 1:numfids
                                    format short g
                                    model_lon = xlon(:,1)
                                    lon_i = length(model_lon)
                                    model_lat = xlat(:,1)
                                    lat_j = length(model_lat)
                                    vals{M} = load(fnames(M).name);
                                    hour = vals{M}(:,1)
                                    minute = vals{M}(:,2)
                                    second = vals{M}(:,3)
                                    lat = vals{M}(:,4)
                                    lon = vals{M}(:,5)
                                                                                                       
                                    for a = 1:length(hour)
                                        for b = 1:lat_j
                                            for c = 1:lon_i
                                                ind_keep = find(([lat(a)] > model_lat((lat_j)-1)
                                                               & [lat(a)] < model_lat(lat_j)) &
                                                              ([lon(a)] > model_lon((lon_i)-1) & [lon(a)] <model_lon(lon_i)))

                                                get_size = size(lat(ind_keep))
                                                
                                                val = get_size(1,1)
                                                subs = [166 333 M]
                                               D = accumarray(subs, val)
                                            end
                                        end
                                    end
                                    text_name = sprintf('grid_view%03d.dat', M)
                                    save(text_name, 'D','-ascii')
                                end
                        end

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us