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

28 次查看(过去 30 天)
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?
function 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
Thanks
  1 个评论
Connor
Connor 2024-3-11
I also have the following in my startupFCn
app.UITable.ColumnFormat = {'char', 'logical'};
app.UITable.ColumnEditable = [true, true];
not sure if this could be making it harder but I thought I should put it in

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2024-3-11
app.Channels = string(subsystem.ChannelNames);
app.Channels will store channel names
app.SelectedChannels = app.Channels(indices(1));
app.SelectedChannels will hold one of the channel names.
if app.SelectedChannels(j,1) == true
There you try to compare the channel name to the logical value true
  2 个评论
Connor
Connor 2024-3-11
the error that I am getting is on the
app.IndvCal(indices(1)) = newData;
line in the callback function. Do you know why that error would be occuring there?
I also thought that
app.Channels(indices(1));
would indicate the column of app.Channels? How could I makee it so then it will hold all the channel names? and do you think I should create another varibale that uses numel(app.channels) to hold the number of channels selected?
the
if app.SelectedChannels(j,1) == true
was suppose to be
if app.SelectedCals(j,1) == true
thanks for catching all of those!
Connor
Connor 2024-3-11
I am also having some difficulty understanding what to do with UITable cell edit. I have had some trouble understanding how to correctly call for columns and/or rows

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by