1

This is my code but I'm sure MATLAB provides a more elegant way to do this. Any thoughts?

all = csvread('TRAINING_i.csv');
actual = csvread('TRAINING_INPUTS.csv');
indTraining = zeros(size(actual,1),1);

for i = 1:size(actual,1)

    indTraining(i,1) = find(ismember(all, actual(i,:), 'rows'));

end

Alert 200 when using jQuery JSON

I have following codes. I used it to get some data from another domain address. In my local network. If anyone can tell me What I did mistake here or give me resolves.

<html>
  <title>Jquery Json</title>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
  <script type="text/javascript">
    jQuery(document).ready(function($){
      $.ajax({ // ajax call starts
        type:"GET",
        async: false,
        cache: false,
        contentType: "application/json; charset=utf-8",
        crossDomain: true,
        //url: "http://10.1.128.107/JsonDohaBackToTemplate/getProjectIDByMAC.svc/media/?projectid=1",
        url: "http://fantasy.premierleague.com/web/api/elements/415/?_=1357337284504", 
        success: function(data) {
          $("body").append(JSON.stringify(data));
        }, 
        error: function(jqXHR, textStatus, errorThrown) {
          alert(jqXHR.status);
        },
      dataType: "jsonp"
    });
  });
  </script>
  </head>

  <body>
  </body>
</html>
4

1 回答 1

1

我不知道我是否完全按照,但我认为这就是你想要做的:

A = [1 2; 
     3 4; 
     5 6; 
     7 8];

B = [3 4; 
     7 8];

for i = 1:size(B,1)

    indTraining(i,1) = find(ismember(A, B(i,:), 'rows'));

end

indTraining 现在是[2, 4]. 这更容易实现,如下所示:

[~, indTraining] = ismember(B, A, 'rows')

不需要循环,也不需要find. 如果您发现自己find在 Matlab 中使用了一个常用函数,则值得首先检查该函数的文档,因为许多常用函数的第二个或第三个输出通常是该函数所做的索引,并且会为您省去麻烦,例如第二个输出max等_

最后,不要all在 matlab 中用作变量名,因为您掩盖了一个非常有用的函数

于 2013-08-14T09:04:53.423 回答