Plotting function, which includes a sum
Mostra commenti meno recenti
Hey,
I am trying to plot the structure function of the temperature of measured data. The Data is in a netcdf. file. I am trying to calculate the sum over k and then plot it over x.
This is my code:
startLoc = [497870 536410];
ncread('030608_nc.100Hz_data1','Tt',startLoc);
Temp=ncread('030608_nc.100Hz_data1','Tt');
I
x=[0:10:10000];
k=[497870,536410];
syms k x
f= matlabfunction(symsum((Temp(k)-Temp(k+x)).^2,k,497870,536410));
plot(x,y);
I then get the following Errors:
>> Sum
Error using internal.matlab.imagesci.nc/read (line 554)
Wrong number of input arguments.
Error in ncread (line 66)
vardata = ncObj.read(varName, varargin{:});
Error in Sum (line 3)
ncread('030608_nc.100Hz_data1','Tt',startLoc);
Thanks for your help :)
1 Commento
Jonas Reibenspies
il 26 Set 2021
Risposte (1)
Walter Roberson
il 26 Set 2021
0 voti
When you provide a start value, you also have to provide a count -- even if you just provide inf as the count.
6 Commenti
Jonas Reibenspies
il 26 Set 2021
Walter Roberson
il 26 Set 2021
Delete the syms k x but keep the assignment to k . Then
f = @(x) reshape(sum((Temp(k(1):k(2)) - Temp((k(1)+k(2)+x(:)))).^2,2), size(x));
y = f(x);
plot(x, y)
Jonas Reibenspies
il 26 Set 2021
Walter Roberson
il 27 Set 2021
Remember you ask to start reading at 497870, so that is the location that is going to be at offset 1 in the resulting array.
Use
k=[497870,536410] - startLoc + 1;
Jonas Reibenspies
il 27 Set 2021
Walter Roberson
il 27 Set 2021
Your setup is suspect. Suppose you had read in all of the data, then examining your desired
f= matlabfunction(symsum((Temp(k)-Temp(k+x)).^2,k,497870,536410));
with x having a minimum value of 0 maximum value of 10000, then you the indices of the Temp values being subtracted would range from 497870+0 to 536410+10000 which is a span of 48541 items. But your count is count = [38540]; which is 10001 short . Note that 497870:536410 is 38541 items.
What is the index of the first item in Temp(k) that is to appear on the left side of the subtraction? What is the index of the last item in Temp(k) that should appear on the left side of the subtraction? What is the index of the last item in Temp(k+x) that should appear on the right side of the subtraction? Last-on-right - first-on-left + 1 is the count of items that you need to read in (we can worry about fixing up the indexing once the correct number of items is retrieved.)
Categorie
Scopri di più su Historical Contests in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!