필터 지우기
필터 지우기

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 (최근 30일)
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');

채택된 답변

Walter Roberson
Walter Roberson 2023년 11월 27일
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
Walter Roberson
Walter Roberson 2023년 11월 27일
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 2023년 11월 27일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by