Error in TextHelper.replaceTableMarkdown (line 133)
DANAJK opened this issue · comments
David Atkinson commented
MATLAB error message:
Error using ==
Arrays have incompatible sizes for this operation.
Error in TextHelper.replaceTableMarkdown (line 133)
rowIdx = numCols == numCols(headerRowIdx);
Error in MatGPT/addChatLog (line 95)
htmlContent = TextHelper.replaceTableMarkdown(content);
Error in MatGPT/send (line 260)
addChatLog(app,m(end).role,m(end).content);
Error in appdesigner.internal.service.AppManagementService/executeCallback (line 172)
callback(appOrUserComponent, event);
Error in matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 62)
newCallback = @(source, event)executeCallback(ams, ...
Related documentation
133 rowIdx = numCols == numCols(headerRowIdx);
The prompt I had used in MatGPT was
Please write a function that checks a table. The function input is a table and this table must have 20 rows and 7 columns. There must be exactly 5 rows where the first three columns all have the value 0. For row number irow where the entries for column 1,2 and 3 are all 0, the value of the fifth column should be equal to scheme.DELTA where scheme = bv2scheme(bv(irow),'SIGNA Premier'). The sixth column should be equal to scheme,delta. The array bv is bv = [90, 500, 1500, 2000, 3000]
In the debugger, at line 133 of TextHelper.m, headerRowIdx
was empty. I noted that splittedStr
contained what looked like a correct response from GPT with perhaps a missing "|" symbol (for OR) where it checks the table size.
K>> splittedStr
splittedStr =
55×1 cell array
{["Sure, here's a function that should do what you're asking for:" ]}
{["" ]}
{["```matlab" ]}
{["function checkTable(tableData)" ]}
{["% CHECKTABLE Check that a table meets certain requirements" ]}
{["% CHECKTABLE(tableData) checks that the input table meets the following requirements:" ]}
{["% - The table has 20 rows and 7 columns" ]}
{["% - There are exactly 5 rows where the first three columns all have the value 0" ]}
{["% - For each of these 5 rows, the value in the fifth column is equal to scheme.DELTA" ]}
{["% where scheme = bv2scheme(bv(irow),'SIGNA Premier')" ]}
{["% - For each of these 5 rows, the value in the sixth column is equal to scheme,delta" ]}
{["%" ]}
{["% Inputs:" ]}
{["% tableData - the table to check (MATLAB table)" ]}
{["" ]}
{["% Define the array of bv values" ]}
{["bv = [90, 500, 1500, 2000, 3000];" ]}
{["" ]}
{["% Check that the table has the correct size" ]}
{["if size(tableData, 1) ~= 20" "" "size(tableData, 2) ~= 7" ]}
{["error('Input table must have 20 rows and 7 columns');" ]}
{["end" ]}
{["" ]}
{["% Find the rows where the first three columns are all 0" ]}
{["zeroRows = find(tableData{:, 1} == 0 & tableData{:, 2} == 0 & tableData{:, 3} == 0);" ]}
{["" ]}
{["% Check that there are exactly 5 such rows" ]}
{["if length(zeroRows) ~= 5" ]}
{["error('Input table must have exactly 5 rows where the first three columns are all 0');" ]}
{["end" ]}
{["" ]}
{["% Loop over the zero rows and check the fifth and sixth columns" ]}
{["for i = 1:length(zeroRows)" ]}
{["irow = zeroRows(i);" ]}
{["scheme = bv2scheme(bv(irow), 'SIGNA Premier');" ]}
{["if tableData{irow, 5} ~= scheme.DELTA" ]}
{["error('Value in fifth column of row %d is incorrect', irow);" ]}
{["end" ]}
{["if ~strcmp(tableData{irow, 6}, sprintf('%s,%s', scheme, delta))" ]}
{["error('Value in sixth column of row %d is incorrect', irow);" ]}
{["end" ]}
{["end" ]}
{["" ]}
{["% If we get here, the table meets all requirements" ]}
{["disp('Table meets all requirements');" ]}
{["end" ]}
{["```" ]}
{["" ]}
{["You can call this function with your table as the input, like this:" ]}
{["" ]}
{["```matlab" ]}
{["checkTable(myTable);" ]}
{["```" ]}
{["" ]}
{["This will check that the input table meets the requirements you specified. If the table does not meet the requirements, an error will be thrown with a message indicating what went wrong. If the table meets all requirements, a message will be displayed indicating that the table meets all requirements."]}
K>>
Toshiaki Takeuchi commented
Thanks, this function is trying to identify markdown table by using "|" in the text, which happens to be "or" operator in MATLAB.
The output from ChatGPT contains the following line, and this is misidentified as table.
if size(table,1) ~= 20 || size(table,2) ~= 7
Hans Scharler commented
Fixed in latest release