This erro occurred while cheking the code - "invalid use of operator"
    7 ビュー (過去 30 日間)
  
       古いコメントを表示
    
function ['input_file', 'output_file'] = min_max_normalization('input_file', 'output_file')
% Завантаження даних
data = load('input_file.m');
x_data = fieldnames(data);
x = data.(x_data{1});
A = 0;
B = 1;
x_min = min(x);
x_max = max(x);
x_norm = ((x - x_min) / (x_max - x_min)) * (B - A) + A;
% Збереження у вихідний файл
save('output_file.m', 'x_norm');
end
mat-file "input_file.m"
K = [97 82 94 87 94 95 84 86 86 95 97 91 87 91 85 92 98 84 95 95];
save("input_file","K");
mat-file "output_file.m"
empty
0 件のコメント
回答 (2 件)
  Les Beckham
      
 2025 年 2 月 28 日
        This line is not valid Matlab syntax and was causing your error message
mat-file "input_file.m"
Maybe this is what you are trying to do???
K = [97 82 94 87 94 95 84 86 86 95 97 91 87 91 85 92 98 84 95 95];
save('input_file.mat', 'K') % <<<<<< NOTE:  .mat files save data, .m files contain code
min_max_normalization %<<<< Call the function!!! See below for results
I'm not sure why you are saving K and x_norm into mat files.
A better way to do this is just pass the input data into the function and return the output data as the output argument. Like this:
returnValue = new_min_max_normalization(K)
% If you are reading/writing data from .mat files with hard-coded names
% your function doesn't need any input arguments or output arguments
% function ['input_file', 'output_file'] = min_max_normalization('input_file', 'output_file')
function min_max_normalization()
    % Завантаження даних
    data = load('input_file.mat');
    x_data = fieldnames(data);
    x = data.(x_data{1});
    A = 0;
    B = 1;
    x_min = min(x);
    x_max = max(x);
    x_norm = ((x - x_min) / (x_max - x_min)) * (B - A) + A;
    % Збереження у вихідний файл
    save('output_file.mat', 'x_norm');
end
% check if output_file.m was saved with the right data
dir *.mat
whos -file output_file.mat
function [x_norm] = new_min_max_normalization(x)
    A = 0;
    B = 1;
    x_min = min(x);
    x_max = max(x);
    x_norm = ((x - x_min) / (x_max - x_min)) * (B - A) + A;
end
1 件のコメント
  Les Beckham
      
 2025 年 2 月 28 日
				Also, if you are just getting started with Matlab, I would highly recommend that you take a couple of hours to go through the free online tutorial: Matlab Onramp
  Image Analyst
      
      
 2025 年 3 月 1 日
        Don't put single quotes around your variables.  And you don't need the output arguments of the filenames.  You can return the x_norm if you want, otherwise you just have to know it's saved in the mat file.
function x_norm = min_max_normalization(input_file_name)
% Save a normalized version of the input data 
% in an output file called "output_file.mat"
x_norm = []; % Initialize an output variable.  Needed in case input file does not exist.
% Завантаження даних
if ~isfile(input_file_name)
    % If file does not exist, exit.
    warningMessage = sprintf('Warning: Input mat file not found:\n%s', input_file_name);
    uiwait(warndlg(warningMessage));
    return;
end
% File exists if you get here.  (I'm assuming the code below to get x works)
data = load(input_file_name) % No single quotes here!
x_data = fieldnames(data)
x = data.(x_data{1});
A = 0;
B = 1;
x_min = min(x);
x_max = max(x);
x_norm = ((x - x_min) / (x_max - x_min)) * (B - A) + A;
% Збереження у вихідний файл
save('output_file.mat', 'x_norm'); % Note: you do want quotes here but the file extension should be .mat.
end
Note that this
A = 0;
B = 1;
x_min = min(x);
x_max = max(x);
x_norm = ((x - x_min) / (x_max - x_min)) * (B - A) + A;
can be done more simply like this:
x_norm = rescale(x, 0, 1);
0 件のコメント
参考
カテゴリ
				Help Center および File Exchange で GPU Computing についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


