How to input a matrix into a variable
    5 ビュー (過去 30 日間)
  
       古いコメントを表示
    
Id like to use a single variable to get multiple answers, for example. 
%% --------
X = [10:10:100]
Y = X+3
%% --------
how can i get an output of Y for every value of X, i just need it to display, even if it overwrites Y's value each time.
3 件のコメント
回答 (1 件)
  Divyam
      
 2025 年 4 月 30 日
        You can either iterate through the array X using a for loop and display values of Y for each value of X or directly use the 'disp' function on the array Y and display all the values of Y that are calculated using the linear equation  .
.
 .
.% Method 1: Iterate through X and display values of Y for each value of X
X = 10:10:100; % Creates a vector [10 20 30 ... 100]
for i = 1:length(X)
    Y = X(i) + 3;
    disp(['X = ' num2str(X(i)) ', Y = ' num2str(Y)])
end
% Method 2: Display all the values of Y that are solutions of the linear
% equation Y = X + 3
X = 10:10:100;
Y = X + 3;
disp(Y)
For more information regarding the 'disp' function, refer to the following documentation: https://www.mathworks.com/help/matlab/ref/disp.html 
0 件のコメント
参考
カテゴリ
				Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



