Filter löschen
Filter löschen

How do I create subscript indicies to be real positive integers or logicals?

3 Ansichten (letzte 30 Tage)
I'm attempting to get data from a .nc file and when running this code I am getting the error of using real positive integers or logicals. Each variable produces exactly what is expected except for spei producing "NaN. The values that should be returned are decimals. How do I get them to return the decimal?
clear
clc
loc=xlsread('Tree_Ring_Data_WI_test.xlsx');%Load treering data only file. SiteNo. species column removed
year=loc(:,4); % formatting
lat=loc(:,2);%latitude
lon=loc(:,1);%longitude
[lonf,latf]=TransLatLon(lon,lat);%Function that translate lat and lon into coordination counts
files=dir('*.nc');%load Temperature files
for y=1:length(files);%Number of years in file
temp=ncread(files(y).name,'spei'); % variable name in climate file
%ind=find(year==y+1900);
%lont=lonf(ind);
%latt=latf(ind);
startm = 12 * (year - 1901)
spei = zeros(1,1380);
for i=1:length(lat);
for j=1:1382;
spei(j)=(temp(lonf(i),latf(i), (j + startm(i)));
end
end
  6 Kommentare
Ayo Deas
Ayo Deas am 26 Jan. 2018
Bearbeitet: Ayo Deas am 26 Jan. 2018
Here is the updated code, taking into consideration all of the suggested actions. As far as nan on the input file, what do you mean by the "input file"? Does it make a difference that the data is stored in a .csv file as opposed to a .xls file and being placed back onto an .xls file that is within the .nc files?
From what I can see on one of the .csv files, there is data(decimals) in every cell in the first column.
Running this code has changed all the values in spei from nan to 0 but still giving the same error message of 'Subscript indices must either be real positive integers or logicals.' which I believe is progress.
clear
clc
loc=xlsread('Tree_Ring_Data_WI_test.xlsx');%Load treering data only file. SiteNo. specises colum removed
year=loc(:,4); % RWI-year change to fit your sheet formate
lat=loc(:,2);%latitude
lon=loc(:,1);%longitude
[lonf,latf]=TransLatLon(lon,lat);%Function that translate lat and lon into coordination counts
files=dir('*.nc');%load Temperature files
for y=1:length(files)%Number of years in your climate file
temp=ncread(files(y).name,'spei'); % variable name in climate file
%ind=find(year==y+1900);
%lont=lonf(ind);
%latt=latf(ind);
startm = 12 * (year - 1901);
spei = zeros(1,1380);
for i=1:length(lat)
spei = zeros(1,1380);
loc(startm(i),30)=spei(1,1,:);
loc(startm(i),31)=spei(1,1,:);
loc(startm(i),32)=spei(1,1,:);
loc(startm(i),33)=spei(1,1,:);
loc(startm(i),34)=spei(1,1,:);
loc(startm(i),35)=spei(1,1,:);
loc(startm(i),36)=spei(1,1,:);
loc(startm(i),37)=spei(1,1,:);
loc(startm(i),38)=spei(1,1,:);
loc(startm(i),39)=spei(1,1,:);
loc(startm(i),40)=spei(1,1,:);
loc(startm(i),41)=spei(1,1,:);
for j=1:1380
spei(i,j)=(temp(lonf(i),latf(i), startm(i)));
end
end
end
Walter Roberson
Walter Roberson am 26 Jan. 2018
I suggest that at the command line you give the command
dbstop if error
and then run the code. When it stops, examine lonf(i) and latf(i) and startm(i)

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Large Files and Big Data finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by