iteration

Load multiple .mat files for processing

假装没事ソ 提交于 2020-01-14 12:03:24
问题 In MatLab I have (after extensive code running) multiple .mat files outputted to .mat files. The actual matlab name of each .mat file is called results but I've used the save command to write them to different files. A small subset of the files looks like this: results_test1_1.mat results_test1_2.mat results_test1_3.mat results_test1_4.mat results_test2_1.mat results_test2_2.mat results_test2_3.mat results_test2_4.mat Now I want to compare the results for each test, which means I have to load

Load multiple .mat files for processing

时光怂恿深爱的人放手 提交于 2020-01-14 12:02:42
问题 In MatLab I have (after extensive code running) multiple .mat files outputted to .mat files. The actual matlab name of each .mat file is called results but I've used the save command to write them to different files. A small subset of the files looks like this: results_test1_1.mat results_test1_2.mat results_test1_3.mat results_test1_4.mat results_test2_1.mat results_test2_2.mat results_test2_3.mat results_test2_4.mat Now I want to compare the results for each test, which means I have to load

Load multiple .mat files for processing

北城以北 提交于 2020-01-14 12:01:50
问题 In MatLab I have (after extensive code running) multiple .mat files outputted to .mat files. The actual matlab name of each .mat file is called results but I've used the save command to write them to different files. A small subset of the files looks like this: results_test1_1.mat results_test1_2.mat results_test1_3.mat results_test1_4.mat results_test2_1.mat results_test2_2.mat results_test2_3.mat results_test2_4.mat Now I want to compare the results for each test, which means I have to load

Multiple iterations

风格不统一 提交于 2020-01-14 08:03:06
问题 Is there a easier, cleaner way to write code like this: (1..10).each do |i| (1..10).each do |j| (1..10).each do |k| (1..10).each do |l| puts "#{i} #{j} #{k} #{l}" end end end end Ideally I'd be able to do something like... (1..10).magic(4) { |i, j, k, l| puts "#{i} #{j} #{k} #{l}" } Or even better... magic(10, 4) { |i, j, k, l| puts "#{i} #{j} #{k} #{l}" } If there's not something built in, how would I write a method like the last one? 回答1: If you're on Ruby 1.9, you can do this: range = (1.

Iterating HashMap on order it has been set

爷,独闯天下 提交于 2020-01-14 06:59:11
问题 I've set a HashMap on certain order but it is iterated on a strange order! Please consider code below: HashMap<String, String> map = new HashMap<String, String>(); map.put("ID", "1"); map.put("Name", "the name"); map.put("Sort", "the sort"); map.put("Type", "the type"); ... for (String key : map.keySet()) { System.out.println(key + ": " + map.get(key)); } and the result: Name: the name Sort: the sort Type: the type ID: 1 I need to iterate it in order i've put the entries. Any help will be

How do you rotate (circular shift) of a Scala collection

有些话、适合烂在心里 提交于 2020-01-13 08:48:34
问题 I can do this quite easily, and cleanly, using a for loop. For instance, if I wanted to traverse a Seq from every element back to itself I would do the following: val seq = Seq(1,2,3,4,5) for (i <- seq.indices) { for (j <- seq.indices) { print(seq(i + j % seq.length)) } } But as I'm looking to fold over the collection, I'm wondering if there is a more idiomatic approach. A recursive approach would allow me to avoid any var s. But basically, I'm wondering if something like the following is

how to parse json response in powershell

荒凉一梦 提交于 2020-01-13 06:52:13
问题 managed to get the JSON data with $R= Invoke-WebRequest -Uri $url -Headers $headers -ContentType "application/json" -Method Get -UseBasicParsing $x = $R.Content | Out-String | ConvertFrom-Json now I've a JSON file like this : { "id": 1000, "name_with_namespace": "myProjectName1", }, { "id": 1001, "name_with_namespace": "myProjectName2", }, { "id": 1002, "name_with_namespace": "myProjectName3", } now I need to extract all the occurence of "name_with_namespace" and "id" where "name_with

Convert this recursive function to iterative

瘦欲@ 提交于 2020-01-12 20:58:27
问题 How can I convert this recursive function to an iterative function? #include <cmath> int M(int H, int T){ if (H == 0) return T; if (H + 1 >= T) return pow(2, T) - 1; return M(H - 1, T - 1) + M(H, T - 1) + 1; } Well it's a 3-line code but it's very hard for me to convert this to an iterative function. Because it has 2 variables. And I don't know anything about Stacks so I couldn't convert that. My purpose for doing this is speed of the function. This function is too slow. I wanted to use map

iOS: Best Way to do This w/o Calling Method 32 Times?

主宰稳场 提交于 2020-01-11 14:07:59
问题 I'm currently retrieving the Top 100 Scores for one of my leaderboards the following way: - (void) retrieveTop100Scores { __block int totalScore = 0; GKLeaderboard *myLB = [[GKLeaderboard alloc] init]; myLB.identifier = [Team currentTeam]; myLB.timeScope = GKLeaderboardTimeScopeAllTime; myLB.playerScope = GKLeaderboardPlayerScopeGlobal; myLB.range = NSMakeRange(1, 100); [myLB loadScoresWithCompletionHandler:^(NSArray *scores, NSError *error) { if (error != nil) { NSLog(@"%@", [error

Recursive to Iterative Pascal's Triangle

谁说我不能喝 提交于 2020-01-11 13:39:34
问题 I wonder how to convert a recursive function/class to an iterative one. I have made a recursive Pascal's triangle, and now need to compare it to an iterative. public class RecursivePascal extends ErrorPascal implements Pascal { private int n; RecursivePascal(int n) throws Exception { super(n); this.n = n; } public void printPascal() { printPascal(n, false); } public void printPascal(boolean upsideDown) { printPascal(n, upsideDown); } private void printPascal(int n, boolean upsideDown) { if (n