필터 지우기
필터 지우기

function arguments block for replacing data in existing excel file

조회 수: 1 (최근 30일)
Davindra Usov
Davindra Usov 2023년 3월 23일
답변: Jack 2023년 3월 29일
Hi,
I am new to function arguments block. I am trying to use it to replace data in an existing excel file data.csv by doing some calculations that use input data from another csv file InputData.csv. Is this the correct format I should use to do this?
function f = replacedata(InputData.csv)
arguments
InputData.csv (1,1) string {mustBeFile(InputData.csv)}
end
% place calculations that use data from InputData.csv file here.
end
  댓글 수: 6
Davindra Usov
Davindra Usov 2023년 3월 29일
is there a way to read in opt variables from this function in another function? data = namedargs2cell(opts)
read(data) does not work
Jack
Jack 2023년 3월 29일
The format you provided for the function definition is not correct.

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

답변 (1개)

Jack
Jack 2023년 3월 29일
The format you provided for the function definition is not correct. Here's a corrected version:
function f = replacedata(input_csv)
% input_csv: file path to InputData.csv
arguments
input_csv (1,1) string {mustBeFile(input_csv)}
end
% Read data from input_csv file
input_data = readmatrix(input_csv);
% Place calculations that use data from InputData.csv file here.
% ...
% Write results to data.csv file
writematrix(results, 'data.csv');
end
In this code, input_csv is the file path to the InputData.csv file. The arguments block is used to validate that the input_csv argument is a string representing a valid file path. You can then use readmatrix to read the data from the InputData.csv file and perform your calculations. Finally, you can use writematrix to write the results to the data.csv file.

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by