MATLAB Answers

Undefined operator '-' for input arguments of type 'struct'.

11 views (last 30 days)
Amy Leach
Amy Leach on 7 Jan 2020
Answered: Cris LaPierre on 7 Jan 2020
I'm trying to edit a program that analyzes change in fluorescence occuring around TTL inputs. I keep getting the following error and am not sure how to fix it:
Undefined operator '-' for input arguments of type 'struct'.
Error in Magazine_training (line 28)
[c, ind] = min(abs(Ts-data.epocs.PtC1(TTL_index, 1))); %returns the position best fit between T and Po0 onset
Here's the portion of code producing the error:
%Takeing TTL times and Delta473 values around TTLs
%data.epocs.PtC1_.onset - Pellet drop
TTL_size = numel(data.epocs.PtC1);
TTL_times = zeros(TTL_size:1);
TTL_temp = zeros(TTL_size:1);
interval_pre = -2000; %milliseconds
interval_post = 15000; %milliseconds
interval_count = abs(interval_pre) + abs(interval_post);
TTL_signal = zeros(interval_count, TTL_size);
for TTL_index = 1:TTL_size %% timestamp
[c, ind] = min(abs(Ts-data.epocs.PtC1(TTL_index, 1))); %returns the position best fit between T and Po0 onset
position = 0;
for interval_ind = interval_pre:interval_post
position = position+1;
TTL_signal(position, TTL_index) = Delta473(ind + interval_ind);
end
TTL_temp(TTL_index) = Delta473(ind); %writes the Delta473 value for the best T+Po0 position
TTL_times(TTL_index) = ind;
end
plot(TTL_signal,'DisplayName','TTL_signal')
csvwrite('pelletdrop.csv',TTL_signal);

  2 Comments

Allen
Allen on 7 Jan 2020
From line 28 that is producing the error, have you defined Ts? If so, can you provide details about Ts such as variable type and/or size?
Amy Leach
Amy Leach on 7 Jan 2020
Yes, Ts is defined earlier with this:
%Create Variables for each Photometry Channel and timestamps
Ch473=data.streams.x473A.data; %GCaMP
Ch405=data.streams.x405A.data; %Isosbestic Control
Ts = ((1:numel(data.streams.x473A.data(1,:))) / data.streams.x473A.fs)'; % Get Ts for samples based on Fs
StartTime=3000; %Set the starting sample(recommend eliminating a few seconds for photoreceiver/LED rise time).
EndTime=length(Ch473)-1000; %Set the ending sample (again, eliminate some).
Fs=data.streams.x473A.fs; %Variable for Fs
Ts=Ts(StartTime:EndTime); % eliminate timestamps before starting sample and after ending.
%Ch473=Ch473(StartTime:EndTime);
%Ch405=Ch405(StartTime:EndTime);

Sign in to comment.

Answers (1)

Cris LaPierre
Cris LaPierre on 7 Jan 2020
Here's a simple case that reproduces the error message
Ts = 10;
data.val = 5;
Ts-data
Undefined operator '-' for input arguments of type 'struct'.
The problem is that data is a structure, not a value. I need to add .val for the code to execute as intended
Ts-data.val
ans =
5
I therefore recommend inspecting you structure data to see if you inadvertantly left off a field name. Perhaps it should be something like this?
[c, ind] = min(abs(Ts-data.epocs.PtC1(TTL_index, 1).val));

  0 Comments

Sign in to comment.

Sign in to answer this question.

Products


Release

R2019a