Creating an array of strings for mapping indexes to values
16 次查看(过去 30 天)
显示 更早的评论
In Python it is easy to implement but wondering how can we do it in MATLAB. Can someone trnslate this toi MATLAB code.
stationmap = [S0,S1,S2,S3,S4,S5,S6,S7,S8,S9]
for i in range(10000):
Station_ID = stationmap[i % 10]
print("For Time {0}, we have station {1}".format(i, Station_ID))
1 个评论
Stephen23
2019-5-4
This is MATLAB, so you can easily get rid of the loop:
>> V = 1:10000;
>> C = {'S0', 'S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9'};
>> T = [num2cell(V);C(1+mod(V-1,numel(C)))];
>> fprintf('For Time {%d}, we have station {%s}\n',T{:})
For Time {1}, we have station {S0}
For Time {2}, we have station {S1}
For Time {3}, we have station {S2}
For Time {4}, we have station {S3}
For Time {5}, we have station {S4}
For Time {6}, we have station {S5}
For Time {7}, we have station {S6}
For Time {8}, we have station {S7}
For Time {9}, we have station {S8}
For Time {10}, we have station {S9}
For Time {11}, we have station {S0}
... lots more lines here
For Time {9993}, we have station {S2}
For Time {9994}, we have station {S3}
For Time {9995}, we have station {S4}
For Time {9996}, we have station {S5}
For Time {9997}, we have station {S6}
For Time {9998}, we have station {S7}
For Time {9999}, we have station {S8}
For Time {10000}, we have station {S9}
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!