Input data from another script

I have a data x with an increment of x = 1:1:100 and I wan to input it to another script such that the another script receive x = 1 to x = 100 instead of the whole array.

답변 (1개)

KSSV
KSSV 2022년 3월 11일

0 개 추천

x = 1:1:100 ;
for i = 1:length(x)
xi = x(i) ;
% input xi to your function and do what you want
end

댓글 수: 4

Apo Li
Apo Li 2022년 3월 11일
I have an error of
Index exceeds the number of array elements. Index must not exceed 1.
Error in untitled2 (line 5)
xi = x(i) ;
KSSV
KSSV 2022년 3월 11일
Show us the full code.
clear all
clc
x = 1:1:100 ;
for i = 1:length(x)
xi = x(i) ;
untitled1;
end
A BIG NO......
What is untitled1??? Come on.....you have to write it like a function, with input x (a single number) and do somehting and take output.
% EXample
clear all
clc
x = 1:1:100 ;
for i = 1:length(x)
xi = x(i) ;
b = Add_three(xi) ;
end
function theoutput = Add_three(theinput)
% do whay you want
theoutput = theinput+3 ; % as a demo I have added three
end

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

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2022년 3월 11일

댓글:

2022년 3월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by