use variable in for loop as function output

 採用された回答

Ameer Hamza
Ameer Hamza 2018 年 5 月 9 日
編集済み: Ameer Hamza 2018 年 5 月 9 日

1 投票

function [ gg{m}] = mykmeans()
shows (although this syntax will not work) that you want to pass only one element to output. Instead, use
function [ gg] = mykmeans()
to pass the whole array.

8 件のコメント

Frank Juang
Frank Juang 2018 年 5 月 9 日
But I want to get the elements in cell.These elements will be used in other part of my code.
Ameer Hamza
Ameer Hamza 2018 年 5 月 9 日
You can still get the element. For example, you call the function like this
% your script
gg = mykmeans(); % you call your function
gg{1} % access the first elemnet by indexing
gg{2} % similarly other elements
Frank Juang
Frank Juang 2018 年 5 月 9 日
Thank you !!
Stephen23
Stephen23 2018 年 5 月 9 日
編集済み: Stephen23 2018 年 5 月 9 日
function [ gg{m}] = mykmeans()
"will only pass one element to output"
@Ameer Hamza: Have you tried this syntax? What actually happened? Can you show any documentation or example where that statement is true?
Frank Juang
Frank Juang 2018 年 5 月 9 日
If I use
% function [ gg{m}] = mykmeans()
, it will occur error :invalid syntax at '{''Possibly a ), }, ] is missing ...
Stephen23
Stephen23 2018 年 5 月 9 日
編集済み: Stephen23 2018 年 5 月 9 日
@Frank Juang: don't worry, that syntax is not supported, even if Ameer Hamza (incorrectly) wrote that it is.
Ameer Hamza
Ameer Hamza 2018 年 5 月 9 日
Oh! I meant to say that, OP just want to pass one element to output, why not pass the whole array. But the wording got incorrect.
Frank Juang
Frank Juang 2018 年 5 月 9 日
that's all right

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by