matlab
api
error
spherepts

MATLAB > Error: Too many output arguments. > 関数の戻り値を指定することで対処する

動作環境
GeForce GTX 1070 (8GB)
ASRock Z170M Pro4S [Intel Z170chipset]
Ubuntu 16.04 LTS desktop amd64
TensorFlow v1.2.1
cuDNN v5.1 for Linux
CUDA v8.0
Python 3.5.2
IPython 6.0.0 -- An enhanced Interactive Python.
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
scipy v0.19.1
geopandas v0.3.0
MATLAB R2017b (Home Edition)

関連

MATLAB > 実装 > 二次元arrayを10回シャッフルする

Error

shuffle_171115.m
% v0.1 Nov. 15, 2017
%    - shuffle 10 times

function shuffle_171115(tri)
    [len1, len2] = size(tri);
    for loop = 1:10
        % get index of [1:N-1]
        pos = round(rand()* (len1 - 2)) + 1;
        % swap
        tri([pos pos+1],:) = tri([pos+1 pos],:)
    end
>> tri = [1 1 1; 2 2 2;];
>> res = shuffle_171115(tri)
Error using shuffle_171115
Too many output arguments.

問題の原因は、shuffle_171115()において戻り値を指定していないこと。

code v0.2

shuffle_171115.m
% v0.2 Nov. 16, 2017
%    - shuffle_171115() returns values
% v0.1 Nov. 15, 2017
%    - shuffle 10 times

function [res] = shuffle_171115(tri)
    [len1, len2] = size(tri);
    for loop = 1:10
        % get index of [1:N-1]
        pos = round(rand()* (len1 - 2)) + 1;
        % swap
        tri([pos pos+1],:) = tri([pos+1 pos],:);
    end
    res = tri;
>> res = shuffle_171115(tri)

res =

     1     1     1
     2     2     2