Reputation: 1
I am working with MATLAB, and I am using data from an excel file. For my stations names I am having trouble reading in the data. EX: row in excel example I need it to accept when some have A at the end, but not have an error if not.
for i = 1:length(data(1:i))
% Process stations
station_info = textscan(char(stations{i}), '%s%4.2f', 'Delimiter', '-');
%Loc{i} = station_info{1}{1};
%statnum(i) = station_info{2};
stationOpts = detectImportOptions(t, 'Sheet', 'gdata', 'DataRange', 'A1:BJ7');
readstations = readtable(t, stationOpts);
% Process samples
%Samp{i} = char(samples{i});
% Process intervals
interval_info = textscan(char(intervals{i}), '%4.2f %4.2f','delimiter','-');
[Samp(i)]=strread(char(samples(i)),'%s%4.2f','-');
[samptop(i) sampbot(i)]=strread(char(intervals(i)),'%4.2f %4.2f','delimiter','-');
end
Warning: Colon operands must be real scalars.
In detectImportOptions (line 423)
ALSO TRIED:
for i=1:length(data(1,:))
[Loc(i) statnum(i)]=strread(char(stations(i)), '%s %4.2f','delimiter','-' ); % find the core numbers for each sample
[Samp(i)]=strread(char(samples(i)),'%s');
[samptop(i) sampbot(i)]=strread(char(intervals(i)),'%4.2f %4.2f','delimiter','-');
end
Unable to perform assignment because the left and right sides have a different number of elements.
here is my code I am having an error with. let me know if you have any suggestions Thanks!
Upvotes: 0
Views: 46
Reputation: 23
I think the below code will meet your requirements:
for i = 1:length(data(1,:))
if endsWith(str(stations(i)), "A") == True
[insert code you want to run when string ends with "A"]
else
"error, no A at the end"
break
end
end
Upvotes: 0