Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6733079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:43:34+00:00 2026-05-26T10:43:34+00:00

I am using 64 bit matlab with 32g of RAM (just so you know).

  • 0

I am using 64 bit matlab with 32g of RAM (just so you know).

I have a file (vector) of 1.3 million numbers (integers). I want to make another vector of the same length, where each point is a weighted average of the entire first vector, weighted by the inverse distance from that position (actually it’s position ^-0.1, not ^-1, but for example purposes). I can’t use matlab’s ‘filter’ function, because it can only average things before the current point, right? To explain more clearly, here’s an example of 3 elements

data = [ 2 6 9 ]
weights = [ 1 1/2 1/3; 1/2 1 1/2; 1/3 1/2 1 ]
results=data*weights= [ 8 11.5 12.666 ]
i.e.
8 = 2*1 + 6*1/2 + 9*1/3
11.5 = 2*1/2 + 6*1 + 9*1/2
12.666 = 2*1/3 + 6*1/2 + 9*1

So each point in the new vector is the weighted average of the entire first vector, weighting by 1/(distance from that position+1).

I could just remake the weight vector for each point, then calculate the results vector element by element, but this requires 1.3 million iterations of a for loop, each of which contains 1.3million multiplications. I would rather use straight matrix multiplication, multiplying a 1×1.3mil by a 1.3milx1.3mil, which works in theory, but I can’t load a matrix that large.

I am then trying to make the matrix using a shell script and index it in matlab so only the relevant column of the matrix is called at a time, but that is also taking a very long time.

I don’t have to do this in matlab, so any advice people have about utilizing such large numbers and getting averages would be appreciated. Since I am using a weight of ^-0.1, and not ^-1, it does not drop off that fast – the millionth point is still weighted at 0.25 compared to the original points weighting of 1, so I can’t just cut it off as it gets big either.

Hope this was clear enough?

Here is the code for the answer below (so it can be formatted?):

data = load('/Users/mmanary/Documents/test/insertion.txt');
data=data.';
total=length(data);
x=1:total;
datapad=[zeros(1,total) data];
weights = ([(total+1):-1:2 1:total]).^(-.4);
weights = weights/sum(weights);
Fdata = fft(datapad);
Fweights = fft(weights);
Fresults = Fdata .* Fweights;
results = ifft(Fresults);
results = results(1:total);
plot(x,results)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:43:35+00:00Added an answer on May 26, 2026 at 10:43 am

    The only sensible way to do this is with FFT convolution, as underpins the filter function and similar. It is very easy to do manually:

    % Simulate some data
    n = 10^6;
    x = randi(10,1,n);
    xpad = [zeros(1,n) x];
    
    % Setup smoothing kernel
    k = 1 ./ [(n+1):-1:2 1:n];
    
    % FFT convolution
    Fx = fft(xpad);
    Fk = fft(k);
    
    Fxk = Fx .* Fk;
    
    xk = ifft(Fxk);
    xk = xk(1:n);
    

    Takes less than half a second for n=10^6!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using matlab R2012a (7.14.0.737) 64-bit on a windows 7 PC. I have
How do we add two 64 bit numbers using 32 bit arithmetic??
I have a costume class called Region and I am using this bit of
I'm using 64 bit matlab r2010a on windows 7 (this may be relevant if
I'm trying to connect to MySQL using MATLAB R2009b 64 bit and the mysql.cpp
How can I write a 1-bit bmp image in Matlab using imwrite or any
i am going to read a TDMS file in matlab using Mexfunction in C
I have Xcode(4.4.1) installed on my mac, and use MATLAB r2011a (64 bit) on
I have a data file generated by hardware. Some data is 4 bit wide
I'm trying to load the following ascii file into MATLAB using load() % some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.