getting the error "Conversion to logical from string is not possible" while using UI table in MATLAB

36 Views Asked by At

I am trying to build an app that collects continuous data and calibrates then displays that data on the apps axes and writes the data to the base workspace so that it can be further manipulated. I want channels to be able to be turned on and off and the calibration of each individual channel to be able to be turned "on" or "off". Currently I am struggling with getting each channel to be able to turn on and off their calibration.

I use the following functions to make and allow my UI table to be editable.

function UpdateUITable(app, subsystem)
         % Return the initial logical values for checkboxes
    app.IndvCal = false(size(subsystem.ChannelNames));
    
    %Channels = cellstr(string(subsystem.ChannelNames));
    app.Channels = string(subsystem.ChannelNames);
    % Create a cell array with channel names and logical values for the checkboxes
    UIData = [app.Channels, app.IndvCal];
    % Set the CellEditCallback for the UITable
    app.UITable.Data = UIData;
end
function UITableCellEdit(app, event)
    indices = event.Indices;
    newData = event.NewData;
    % Update the logical array based on checkbox changes
    app.IndvCal(indices(1)) = newData;
    % Update the selected channels variables
    app.SelectedCal = app.Channels(app.IndvCal);
    app.SelectedChannels = app.Channels(indices(1));
    % Call the function that uses the selected channels (e.g., data calibration)
    updateChannelMeasurementComponents(app)
end

I use these values to determine what data that I have will be calibrated with the following function. I am getting this logical string error and I am unsure why. I want the channels that are selected to be displayed in my graph

function updateLivePlot(app)
   % Update the live plot
   if isempty(app.DataFIFOBufferch1) || isempty(app.SelectedChannels)
       return
   end
   % Disable interactivity
   disableDefaultInteractivity(app.LiveAxes);
   % Keep the colors the same after each new data point
   app.LiveAxes.ColorOrderIndex = 1;
   if isempty(app.LivePlotLine)
       % First-Time Setup
       app.LivePlotLine = plot(app.LiveAxes, app.TimestampsFIFOBuffer, app.DataFIFOBufferch1(:, app.SelectedChannels));
   else
       % Update existing plot
       for j = 1:numel(app.SelectedChannels)
           % Check if the line needs to be extended
           if numel(app.LivePlotLine) < j || isempty(app.LivePlotLine(j))
               % Use existing axes to plot
               app.LivePlotLine(j) = plot(app.LiveAxes, app.TimestampsFIFOBuffer, app.DataFIFOBufferch1(:, app.SelectedChannels(j,1)));
           else
               % Update existing line
               set(app.LivePlotLine(j), 'XData', app.TimestampsFIFOBuffer, 'YData', app.DataFIFOBufferch1(:, app.SelectedChannels(j,1)));
           end
       end
   end
   if numel(app.TimestampsFIFOBuffer) > 1
       xlim(app.LiveAxes, [app.TimestampsFIFOBuffer(1), app.TimestampsFIFOBuffer(end)]);
   end
end

and the graph plots the calibrated and raw data based on the following function. The data feeds into all function continously atm and when channels are selected in the UI table that (in theory) change what is being displayed on the graph. I am wondering If i should add another column to my UI table that can be another logical that would keep track if the channel is off or on and also keep the calibration logical?

unction calibratedData = calibrateData(app,data, slopes, intercepts)
% Calibrate the data using slopes and intercepts
calibratedData = data;
for j = 1:numel(app.SelectedChannels)
    if app.SelectedChannels(j,1) == true 
        calibratedData(:,j) = calibratedData(:,j) * slopes(:,j) + intercepts(:,j);
    elseif app.SelectedChannels(j,1) == false
        calibratedData = app.data; 
        app.TimewindowEditField.Value = 10;
    else
        calibratedData = app.data; 
    end
end
end

I also have the following in my startupFCn

app.UITable.ColumnFormat = {'char', 'logical'};
app.UITable.ColumnEditable = [true, true];

Thanks

0

There are 0 best solutions below