Why does this give me the "Unable to perform assignment because the left and right sides have a different number of elements." error?
    8 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
Hi,
I'm trying to convert my code into an app as an exercise. I'm trying to get a list to update its items to contain all components.
function CreateComponentButtonPushed(app, event)
            new_comp = comp(app.ComponentNameEditField.Value, length(app.components)+1, app.MolarMassgmolEditField.Value);
            new_comp.setAntoine([app.AntoineEqnAEditField.Value, app.AntoineEqnBEditField.Value, app.AntoineEqnCEditField.Value]);
            app.components = [app.components, new_comp];
            display_names = zeros(length(app.components), 1);
            for i = 1:length(display_names)
                %Set the current value to the name of the component
                display_names(i) = app.components(i).name;
            end
            disp(display_names);
            %Supposed to change the list in the app to contain all the new
            %display names
            app.ComponentsListBox.Items = display_names;
end
This is throwing up an error in the display_names(i) = app.components(i).name line. What's the issue here?
Thanks in advance.
0 Kommentare
Antworten (2)
  Harsh Saxena
      
 am 5 Jun. 2023
        Hi, 
Maybe this error is occuring due to the fact that app.components.name(i) is a character array, so MATLAB considers left hand side as a double value while the right hand side as an array of characters. Try initializing the display_names as:
display_names = strings([length(app.components), 1]);
Hope this helps!
0 Kommentare
  Image Analyst
      
      
 am 6 Jun. 2023
        
      Bearbeitet: Image Analyst
      
      
 am 6 Jun. 2023
  
      Perhaps make it a cell array:
numControls = length(app.components)
display_names = cell(numControls, 1);
for k = 1 : numControls % Don't use i as an iterator.
    % Set the current value to the name of the component
    display_names{k} = app.components(k).name; % Use braces, not parentheses.
end
See the FAQ:
If you have any more questions, then attach your .mlapp file, and any data needed at run time, with the paperclip icon after you read this:
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


