Plot graph based on exist uitable data

1 vue (au cours des 30 derniers jours)
Anewa
Anewa le 10 Jan 2021
My GUI has a editable uitable. I set it 20x2. But based on user data, the table is not full. My slope and intercept code only run when the table is full. If not it disp NaN. How can i code it based on only existing data on uitable?
Data = str2double(get(handles.TableField,'Data'))
t = Data(:,1)
Raw = Data(:,2)
C = log(raw)
plot(t,C)
P=polyfit(t,C,1)
slope = P(1)
set(handles.text8,'String',slope);
guidata(hObject, handles);
intercept = P(2)
set(handles.text14,'String',intercept);
  1 commentaire
fitriyanni jeff
fitriyanni jeff le 10 Jan 2021
i also have the same problem

Connectez-vous pour commenter.

Réponses (1)

Deepak
Deepak le 5 Sep 2024
Hi @Anewa,
I understand that you have created an editable UI Table with dimensions 20x2, and you want to fill the table based on user data. However, the user data has missing values, and your code works only when the user data is complete, so that the table gets filled completely.
To handle the cases where UI Table is not fully populated, we can first filter out the rows that containNaN” values, before performing the calculations. To do that, we can use logical indexing in MATLAB. Below expression returns a logical array indicating rows without “NaN” values.
rows = ~any(isnan(Data), 2);
Please find attached the documentation of “isnan” function in MATLAB for reference:
Here is the complete MATLAB code that addresses the task:
Data = get(handles.TableField, 'Data');
Data = str2double(Data);
% Remove rows with NaN values
Data = Data(~any(isnan(Data), 2), :);
% Check if there is enough data to perform the calculation
if size(Data, 1) >= 2
t = Data(:, 1);
raw = Data(:, 2);
C = log(raw);
plot(t, C);
P = polyfit(t, C, 1);
slope = P(1);
intercept = P(2);
% Update the GUI with slope and intercept
set(handles.text8, 'String', slope);
set(handles.text14, 'String', intercept);
else
% Handle the case where there is not enough data
set(handles.text8, 'String', 'Insufficient data');
set(handles.text14, 'String', 'Insufficient data');
end
% Update the handles structure
guidata(hObject, handles);
I anticipate this will resolve the issue.

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by