フィルターのクリア

Problem with calling the function

1 回表示 (過去 30 日間)
Cristian
Cristian 2014 年 5 月 9 日
回答済み: dpb 2014 年 5 月 9 日
Task: Write a function allparts that will read in lists of part numbers for parts produced by two factories. These are contained in data files called ‘xyparts.dat’ and ‘qzparts.dat’. The function will return a vector of all parts produced, in sorted order (with no repeats). Calling the function would return the following:
>> partslist = allparts
partslist =
102 111 123 145 333 456 876 903
Here is what I get:
function outv=allparts(xyparts,qzparts)
clc
load xyparts.dat;
load qzparts.dat;
un=union(xyparts,qzparts);
disp('The result of the function:')
disp(sort(un))
end
Please, help to fix the problem!
  3 件のコメント
Star Strider
Star Strider 2014 年 5 月 9 日
Perusing the documentation on Set Operations might be worthwhile.
Cristian
Cristian 2014 年 5 月 9 日
I don't understand why in allparts do not indicate the input arguments:
partslist = allparts %<---???
partslist =
102 111 123 145 333 456 876 903

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

採用された回答

dpb
dpb 2014 年 5 月 9 日
...why in allparts do not indicate the input arguments...
Because that's the way the assignment was written--actually I see that I whiffed on that portion of your solution that doesn't match the problem description.
I'd give your solution the better marks for factorization as it is more general but the instructions say to build it specific for the two data files. Your function is also built upon that and there's no need or use for the two arguments as written; the values for the variables are obtained from the load operations and since Matlab doesn't modify arguments in the calling context, they won't be transferred back to the higher level that way. Hence you should just eliminate them from your function definition.
Your code still has the problems I outlined previously that don't match the assignment requirements.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by