Filter löschen
Filter löschen

Unable to perform assignment because the size of the left side is 128-by-20 and the size of the right side is 1-by-20.

2 Ansichten (letzte 30 Tage)
load('FTP variables');
Error using load
Unable to find file or directory 'FTP variables'.
filename = 'FTP variables.xlsx';
data_name = who;
length = size(data_name,1);
data_array = 0;
ArrayNum=1;
for i = 1:length
name = char(data_name(i,1));
Temp_exp = strcat('data_value = ',name,';');
eval('base',Temp_exp);
data_array = size(data_value,2);
if data_array == 1
output(:,ArrayNum) = data_value;
else
output(:,ArrayNum:data_array+ArrayNum-1) = data_value;
end
for j=ArrayNum:ArrayNum+data_array-1
signal_name(1,j) = data_name(i,1);
end
ArrayNum=ArrayNum+data_array;
end
xlswrite(filename, output, 1, 'A2' );
xlswrite(filename, signal_name ,1,'A1');

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 27 Nov. 2023
Don't do that. Do not construct dynamic variable name references.
data_name = who;
One of the names that is going to be picked up when you do that is the filename that was assigned in the line before. That is going to be a 1 x something char array, so data_array == 1 is false, so the "else" is going to be in effect, and you are going to try to save the single-row filename into multiple rows of output
You need to revamp your logic a fair bit.
datastruct = load('FTP variables');
data_name = fieldnames(datastruct);
num_fields = length(data_name);
outputs = struct2cell(datastruct);
%pad the entries to match the longest number of rows
maxrows = max(cellfun(@(C) size(C,1), outputs));
outputs = cellfun(@(C) [C;zeros(maxrows-size(C,1), size(C,2))], outputs, 'uniform', 0);
%now put everything together into one 2D array
output = horzcat(outputs{:});
%generate signal names
signal_names = repelem(data_name, cellfun(@(C) size(C,2), outputs));
%now do any appropriate writing to files
  5 Kommentare
Walter Roberson
Walter Roberson am 27 Nov. 2023
whos -file 'FTP Variables.mat'
please show us the results and tell us which of the variables you want to write to a file
Youngjin
Youngjin am 27 Nov. 2023
I just want to write down the variables in the workspace along with their names in an Excel file.The Simulink content in the file is my mistake.Usually, it is necessary to check other people's workspace variables and write them down in Excel to report them.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by