Creating a n*2 array from a variable in workspace
古いコメントを表示
I have a variable on my workspace, in which i have n*2 elements ( 'n' rows and 2 columns). I wanna create an array to do some computation on all the elemental pairs of that variable, such that x1,y1... How can i do that ???
4 件のコメント
madhan ravi
2019 年 1 月 30 日
x=data(:,1); % where data is the variable in the workspace
y=data(:,2);
deep Dhillon
2019 年 1 月 30 日
madhan ravi
2019 年 1 月 30 日
for k=1:size(data,1)
somefunction(data(k,:)) %like this ?
end
deep Dhillon
2019 年 1 月 30 日
採用された回答
その他の回答 (2 件)
Please read this below:
eval and evalin are not recommended. Why you are not just creating a function that gets your nx2 array as the input variable? And a for loop that gets your array's each row one by one?
For example:
function myOutputs = myAlgorithm(centers)
c = [];
for i = 1:size(centers,1)
x = centers(i,1);
y = centers(i,2);
% do what you want with your x and y and then next iteration x and y will be your next row of your array
c = [c x*y]; % just an example
end
myOutputs = c % just an example
end
1 件のコメント
deep Dhillon
2019 年 2 月 1 日
編集済み: Image Analyst
2019 年 2 月 2 日
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

