how can I extract values from a struct matrix that contains only one value to make single matrix from it?

3 次查看（过去 30 天）
hsnHkl 2024-2-5

I have This code down below that contains one value . I want extract the values so that I can plot a line plot . Instead of a line plot I can only obtain a plot down below
n=1000
n = 1000
for j=1:n
fnu=sprintf('u%d',j);
fnv=sprintf('v%d',j);
u = U_at_right_top.(fnu).u;
%v = V_at_right_top.(fnv).v;
plot(j,u,'x--')
hold on
end
1 个评论显示 -1更早的评论隐藏 -1更早的评论
Stephen23 2024-2-5

S = S.U_at_right_top
S = struct with fields:
u1: [1×1 struct] u2: [1×1 struct] u3: [1×1 struct] u4: [1×1 struct] u5: [1×1 struct] u6: [1×1 struct] u7: [1×1 struct] u8: [1×1 struct] u9: [1×1 struct] u10: [1×1 struct] u11: [1×1 struct] u12: [1×1 struct] u13: [1×1 struct] u14: [1×1 struct] u15: [1×1 struct] u16: [1×1 struct] u17: [1×1 struct] u18: [1×1 struct] u19: [1×1 struct] u20: [1×1 struct] u21: [1×1 struct] u22: [1×1 struct] u23: [1×1 struct] u24: [1×1 struct] u25: [1×1 struct] u26: [1×1 struct] u27: [1×1 struct] u28: [1×1 struct] u29: [1×1 struct] u30: [1×1 struct] u31: [1×1 struct] u32: [1×1 struct] u33: [1×1 struct] u34: [1×1 struct] u35: [1×1 struct] u36: [1×1 struct] u37: [1×1 struct] u38: [1×1 struct] u39: [1×1 struct] u40: [1×1 struct] u41: [1×1 struct] u42: [1×1 struct] u43: [1×1 struct] u44: [1×1 struct] u45: [1×1 struct] u46: [1×1 struct] u47: [1×1 struct] u48: [1×1 struct] u49: [1×1 struct] u50: [1×1 struct] u51: [1×1 struct] u52: [1×1 struct] u53: [1×1 struct] u54: [1×1 struct] u55: [1×1 struct] u56: [1×1 struct] u57: [1×1 struct] u58: [1×1 struct] u59: [1×1 struct] u60: [1×1 struct] u61: [1×1 struct] u62: [1×1 struct] u63: [1×1 struct] u64: [1×1 struct] u65: [1×1 struct] u66: [1×1 struct] u67: [1×1 struct] u68: [1×1 struct] u69: [1×1 struct] u70: [1×1 struct] u71: [1×1 struct] u72: [1×1 struct] u73: [1×1 struct] u74: [1×1 struct] u75: [1×1 struct] u76: [1×1 struct] u77: [1×1 struct] u78: [1×1 struct] u79: [1×1 struct] u80: [1×1 struct] u81: [1×1 struct] u82: [1×1 struct] u83: [1×1 struct] u84: [1×1 struct] u85: [1×1 struct] u86: [1×1 struct] u87: [1×1 struct] u88: [1×1 struct] u89: [1×1 struct] u90: [1×1 struct] u91: [1×1 struct] u92: [1×1 struct] u93: [1×1 struct] u94: [1×1 struct] u95: [1×1 struct] u96: [1×1 struct] u97: [1×1 struct] u98: [1×1 struct] u99: [1×1 struct] u100: [1×1 struct] u101: [1×1 struct] u102: [1×1 struct] u103: [1×1 struct] u104: [1×1 struct] u105: [1×1 struct] u106: [1×1 struct] u107: [1×1 struct] u108: [1×1 struct] u109: [1×1 struct] u110: [1×1 struct] u111: [1×1 struct] u112: [1×1 struct] u113: [1×1 struct] u114: [1×1 struct] u115: [1×1 struct] u116: [1×1 struct] u117: [1×1 struct] u118: [1×1 struct] u119: [1×1 struct] u120: [1×1 struct] u121: [1×1 struct] u122: [1×1 struct] u123: [1×1 struct] u124: [1×1 struct] u125: [1×1 struct] u126: [1×1 struct] u127: [1×1 struct] u128: [1×1 struct] u129: [1×1 struct] u130: [1×1 struct] u131: [1×1 struct] u132: [1×1 struct] u133: [1×1 struct] u134: [1×1 struct] u135: [1×1 struct] u136: [1×1 struct] u137: [1×1 struct] u138: [1×1 struct] u139: [1×1 struct] u140: [1×1 struct] u141: [1×1 struct] u142: [1×1 struct] u143: [1×1 struct] u144: [1×1 struct] u145: [1×1 struct] u146: [1×1 struct] u147: [1×1 struct] u148: [1×1 struct] u149: [1×1 struct] u150: [1×1 struct] u151: [1×1 struct] u152: [1×1 struct] u153: [1×1 struct] u154: [1×1 struct] u155: [1×1 struct] u156: [1×1 struct] u157: [1×1 struct] u158: [1×1 struct] u159: [1×1 struct] u160: [1×1 struct] u161: [1×1 struct] u162: [1×1 struct] u163: [1×1 struct] u164: [1×1 struct] u165: [1×1 struct] u166: [1×1 struct] u167: [1×1 struct] u168: [1×1 struct] u169: [1×1 struct] u170: [1×1 struct] u171: [1×1 struct] u172: [1×1 struct] u173: [1×1 struct] u174: [1×1 struct] u175: [1×1 struct] u176: [1×1 struct] u177: [1×1 struct] u178: [1×1 struct] u179: [1×1 struct] u180: [1×1 struct] u181: [1×1 struct] u182: [1×1 struct] u183: [1×1 struct] u184: [1×1 struct] u185: [1×1 struct] u186: [1×1 struct] u187: [1×1 struct] u188: [1×1 struct] u189: [1×1 struct] u190: [1×1 struct] u191: [1×1 struct] u192: [1×1 struct] u193: [1×1 struct] u194: [1×1 struct] u195: [1×1 struct] u196: [1×1 struct] u197: [1×1 struct] u198: [1×1 struct] u199: [1×1 struct] u200: [1×1 struct] u201: [1×1 struct] u202: [1×1 struct] u203: [1×1 struct] u204: [1×1 struct] u205: [1×1 struct] u206: [1×1 struct] u207: [1×1 struct] u208: [1×1 struct] u209: [1×1 struct] u210: [1×1 struct] u211: [1×1 struct] u212: [1×1 struct] u213: [1×1 struct] u214: [1×1 struct] u215: [1×1 struct] u216: [1×1 struct] u217: [1×1 struct] u218: [1×1 struct] u219: [1×1 struct] u220: [1×1 struct] u221: [1×1 struct] u222: [1×1 struct] u223: [1×1 struct] u224: [1×1 struct] u225: [1×1 struct] u226: [1×1 struct] u227: [1×1 struct] u228: [1×1 struct] u229: [1×1 struct] u230: [1×1 struct] u231: [1×1 struct] u232: [1×1 struct] u233: [1×1 struct] u234: [1×1 struct] u235: [1×1 struct] u236: [1×1 struct] u237: [1×1 struct] u238: [1×1 struct] u239: [1×1 struct] u240: [1×1 struct] u241: [1×1 struct] u242: [1×1 struct] u243: [1×1 struct] u244: [1×1 struct] u245: [1×1 struct] u246: [1×1 struct] u247: [1×1 struct] u248: [1×1 struct] u249: [1×1 struct] u250: [1×1 struct] u251: [1×1 struct] u252: [1×1 struct] u253: [1×1 struct] u254: [1×1 struct] u255: [1×1 struct] u256: [1×1 struct] u257: [1×1 struct] u258: [1×1 struct] u259: [1×1 struct] u260: [1×1 struct] u261: [1×1 struct] u262: [1×1 struct] u263: [1×1 struct] u264: [1×1 struct] u265: [1×1 struct] u266: [1×1 struct] u267: [1×1 struct] u268: [1×1 struct] u269: [1×1 struct] u270: [1×1 struct] u271: [1×1 struct] u272: [1×1 struct] u273: [1×1 struct] u274: [1×1 struct] u275: [1×1 struct] u276: [1×1 struct] u277: [1×1 struct] u278: [1×1 struct] u279: [1×1 struct] u280: [1×1 struct] u281: [1×1 struct] u282: [1×1 struct] u283: [1×1 struct] u284: [1×1 struct] u285: [1×1 struct] u286: [1×1 struct] u287: [1×1 struct] u288: [1×1 struct] u289: [1×1 struct] u290: [1×1 struct] u291: [1×1 struct] u292: [1×1 struct] u293: [1×1 struct] u294: [1×1 struct] u295: [1×1 struct] u296: [1×1 struct] u297: [1×1 struct] u298: [1×1 struct] u299: [1×1 struct] u300: [1×1 struct] u301: [1×1 struct] u302: [1×1 struct] u303: [1×1 struct] u304: [1×1 struct] u305: [1×1 struct] u306: [1×1 struct] u307: [1×1 struct] u308: [1×1 struct] u309: [1×1 struct] u310: [1×1 struct] u311: [1×1 struct] u312: [1×1 struct] u313: [1×1 struct] u314: [1×1 struct] u315: [1×1 struct] u316: [1×1 struct] u317: [1×1 struct] u318: [1×1 struct] u319: [1×1 struct] u320: [1×1 struct] u321: [1×1 struct] u322: [1×1 struct] u323: [1×1 struct] u324: [1×1 struct] u325: [1×1 struct] u326: [1×1 struct] u327: [1×1 struct] u328: [1×1 struct] u329: [1×1 struct] u330: [1×1 struct] u331: [1×1 struct] u332: [1×1 struct] u333: [1×1 struct] u334: [1×1 struct] u335: [1×1 struct] u336: [1×1 struct] u337: [1×1 struct] u338: [1×1 struct] u339: [1×1 struct] u340: [1×1 struct] u341: [1×1 struct] u342: [1×1 struct] u343: [1×1 struct] u344: [1×1 struct] u345: [1×1 struct] u346: [1×1 struct] u347: [1×1 struct] u348: [1×1 struct] u349: [1×1 struct] u350: [1×1 struct] u351: [1×1 struct] u352: [1×1 struct] u353: [1×1 struct] u354: [1×1 struct] u355: [1×1 struct] u356: [1×1 struct] u357: [1×1 struct] u358: [1×1 struct] u359: [1×1 struct] u360: [1×1 struct] u361: [1×1 struct] u362: [1×1 struct] u363: [1×1 struct] u364: [1×1 struct] u365: [1×1 struct] u366: [1×1 struct] u367: [1×1 struct] u368: [1×1 struct] u369: [1×1 struct] u370: [1×1 struct] u371: [1×1 struct] u372: [1×1 struct] u373: [1×1 struct] u374: [1×1 struct] u375: [1×1 struct] u376: [1×1 struct] u377: [1×1 struct] u378: [1×1 struct] u379: [1×1 struct] u380: [1×1 struct] u381: [1×1 struct] u382: [1×1 struct] u383: [1×1 struct] u384: [1×1 struct] u385: [1×1 struct] u386: [1×1 struct] u387: [1×1 struct] u388: [1×1 struct] u389: [1×1 struct] u390: [1×1 struct] u391: [1×1 struct] u392: [1×1 struct] u393: [1×1 struct] u394: [1×1 struct] u395: [1×1 struct] u396: [1×1 struct] u397: [1×1 struct] u398: [1×1 struct] u399: [1×1 struct] u400: [1×1 struct] u401: [1×1 struct] u402: [1×1 struct] u403: [1×1 struct] u404: [1×1 struct] u405: [1×1 struct] u406: [1×1 struct] u407: [1×1 struct] u408: [1×1 struct] u409: [1×1 struct] u410: [1×1 struct] u411: [1×1 struct] u412: [1×1 struct] u413: [1×1 struct] u414: [1×1 struct] u415: [1×1 struct] u416: [1×1 struct] u417: [1×1 struct] u418: [1×1 struct] u419: [1×1 struct] u420: [1×1 struct] u421: [1×1 struct] u422: [1×1 struct] u423: [1×1 struct] u424: [1×1 struct] u425: [1×1 struct] u426: [1×1 struct] u427: [1×1 struct] u428: [1×1 struct] u429: [1×1 struct] u430: [1×1 struct] u431: [1×1 struct] u432: [1×1 struct] u433: [1×1 struct] u434: [1×1 struct] u435: [1×1 struct] u436: [1×1 struct] u437: [1×1 struct] u438: [1×1 struct] u439: [1×1 struct] u440: [1×1 struct] u441: [1×1 struct] u442: [1×1 struct] u443: [1×1 struct] u444: [1×1 struct] u445: [1×1 struct] u446: [1×1 struct] u447: [1×1 struct] u448: [1×1 struct] u449: [1×1 struct] u450: [1×1 struct] u451: [1×1 struct] u452: [1×1 struct] u453: [1×1 struct] u454: [1×1 struct] u455: [1×1 struct] u456: [1×1 struct] u457: [1×1 struct] u458: [1×1 struct] u459: [1×1 struct] u460: [1×1 struct] u461: [1×1 struct] u462: [1×1 struct] u463: [1×1 struct] u464: [1×1 struct] u465: [1×1 struct] u466: [1×1 struct] u467: [1×1 struct] u468: [1×1 struct] u469: [1×1 struct] u470: [1×1 struct] u471: [1×1 struct] u472: [1×1 struct] u473: [1×1 struct] u474: [1×1 struct] u475: [1×1 struct] u476: [1×1 struct] u477: [1×1 struct] u478: [1×1 struct] u479: [1×1 struct] u480: [1×1 struct] u481: [1×1 struct] u482: [1×1 struct] u483: [1×1 struct] u484: [1×1 struct] u485: [1×1 struct] u486: [1×1 struct] u487: [1×1 struct] u488: [1×1 struct] u489: [1×1 struct] u490: [1×1 struct] u491: [1×1 struct] u492: [1×1 struct] u493: [1×1 struct] u494: [1×1 struct] u495: [1×1 struct] u496: [1×1 struct] u497: [1×1 struct] u498: [1×1 struct] u499: [1×1 struct] u500: [1×1 struct] u501: [1×1 struct] u502: [1×1 struct] u503: [1×1 struct] u504: [1×1 struct] u505: [1×1 struct] u506: [1×1 struct] u507: [1×1 struct] u508: [1×1 struct] u509: [1×1 struct] u510: [1×1 struct] u511: [1×1 struct] u512: [1×1 struct] u513: [1×1 struct] u514: [1×1 struct] u515: [1×1 struct] u516: [1×1 struct] u517: [1×1 struct] u518: [1×1 struct] u519: [1×1 struct] u520: [1×1 struct] u521: [1×1 struct] u522: [1×1 struct] u523: [1×1 struct] u524: [1×1 struct] u525: [1×1 struct] u526: [1×1 struct] u527: [1×1 struct] u528: [1×1 struct] u529: [1×1 struct] u530: [1×1 struct] u531: [1×1 struct] u532: [1×1 struct] u533: [1×1 struct] u534: [1×1 struct] u535: [1×1 struct] u536: [1×1 struct] u537: [1×1 struct] u538: [1×1 struct] u539: [1×1 struct] u540: [1×1 struct] u541: [1×1 struct] u542: [1×1 struct] u543: [1×1 struct] u544: [1×1 struct] u545: [1×1 struct] u546: [1×1 struct] u547: [1×1 struct] u548: [1×1 struct] u549: [1×1 struct] u550: [1×1 struct] u551: [1×1 struct] u552: [1×1 struct] u553: [1×1 struct] u554: [1×1 struct] u555: [1×1 struct] u556: [1×1 struct] u557: [1×1 struct] u558: [1×1 struct] u559: [1×1 struct] u560: [1×1 struct] u561: [1×1 struct] u562: [1×1 struct] u563: [1×1 struct] u564: [1×1 struct] u565: [1×1 struct] u566: [1×1 struct] u567: [1×1 struct] u568: [1×1 struct] u569: [1×1 struct] u570: [1×1 struct] u571: [1×1 struct] u572: [1×1 struct] u573: [1×1 struct] u574: [1×1 struct] u575: [1×1 struct] u576: [1×1 struct] u577: [1×1 struct] u578: [1×1 struct] u579: [1×1 struct] u580: [1×1 struct] u581: [1×1 struct] u582: [1×1 struct] u583: [1×1 struct] u584: [1×1 struct] u585: [1×1 struct] u586: [1×1 struct] u587: [1×1 struct] u588: [1×1 struct] u589: [1×1 struct] u590: [1×1 struct] u591: [1×1 struct] u592: [1×1 struct] u593: [1×1 struct] u594: [1×1 struct] u595: [1×1 struct] u596: [1×1 struct] u597: [1×1 struct] u598: [1×1 struct] u599: [1×1 struct] u600: [1×1 struct] u601: [1×1 struct] u602: [1×1 struct] u603: [1×1 struct] u604: [1×1 struct] u605: [1×1 struct] u606: [1×1 struct] u607: [1×1 struct] u608: [1×1 struct] u609: [1×1 struct] u610: [1×1 struct] u611: [1×1 struct] u612: [1×1 struct] u613: [1×1 struct] u614: [1×1 struct] u615: [1×1 struct] u616: [1×1 struct] u617: [1×1 struct] u618: [1×1 struct] u619: [1×1 struct] u620: [1×1 struct] u621: [1×1 struct] u622: [1×1 struct] u623: [1×1 struct] u624: [1×1 struct] u625: [1×1 struct] u626: [1×1 struct] u627: [1×1 struct] u628: [1×1 struct] u629: [1×1 struct] u630: [1×1 struct] u631: [1×1 struct] u632: [1×1 struct] u633: [1×1 struct] u634: [1×1 struct] u635: [1×1 struct] u636: [1×1 struct] u637: [1×1 struct] u638: [1×1 struct] u639: [1×1 struct] u640: [1×1 struct] u641: [1×1 struct] u642: [1×1 struct] u643: [1×1 struct] u644: [1×1 struct] u645: [1×1 struct] u646: [1×1 struct] u647: [1×1 struct] u648: [1×1 struct] u649: [1×1 struct] u650: [1×1 struct] u651: [1×1 struct] u652: [1×1 struct] u653: [1×1 struct] u654: [1×1 struct] u655: [1×1 struct] u656: [1×1 struct] u657: [1×1 struct] u658: [1×1 struct] u659: [1×1 struct] u660: [1×1 struct] u661: [1×1 struct] u662: [1×1 struct] u663: [1×1 struct] u664: [1×1 struct] u665: [1×1 struct] u666: [1×1 struct] u667: [1×1 struct] u668: [1×1 struct] u669: [1×1 struct] u670: [1×1 struct] u671: [1×1 struct] u672: [1×1 struct] u673: [1×1 struct] u674: [1×1 struct] u675: [1×1 struct] u676: [1×1 struct] u677: [1×1 struct] u678: [1×1 struct] u679: [1×1 struct] u680: [1×1 struct] u681: [1×1 struct] u682: [1×1 struct] u683: [1×1 struct] u684: [1×1 struct] u685: [1×1 struct] u686: [1×1 struct] u687: [1×1 struct] u688: [1×1 struct] u689: [1×1 struct] u690: [1×1 struct] u691: [1×1 struct] u692: [1×1 struct] u693: [1×1 struct] u694: [1×1 struct] u695: [1×1 struct] u696: [1×1 struct] u697: [1×1 struct] u698: [1×1 struct] u699: [1×1 struct] u700: [1×1 struct] u701: [1×1 struct] u702: [1×1 struct] u703: [1×1 struct] u704: [1×1 struct] u705: [1×1 struct] u706: [1×1 struct] u707: [1×1 struct] u708: [1×1 struct] u709: [1×1 struct] u710: [1×1 struct] u711: [1×1 struct] u712: [1×1 struct] u713: [1×1 struct] u714: [1×1 struct] u715: [1×1 struct] u716: [1×1 struct] u717: [1×1 struct] u718: [1×1 struct] u719: [1×1 struct] u720: [1×1 struct] u721: [1×1 struct] u722: [1×1 struct] u723: [1×1 struct] u724: [1×1 struct] u725: [1×1 struct] u726: [1×1 struct] u727: [1×1 struct] u728: [1×1 struct] u729: [1×1 struct] u730: [1×1 struct] u731: [1×1 struct] u732: [1×1 struct] u733: [1×1 struct] u734: [1×1 struct] u735: [1×1 struct] u736: [1×1 struct] u737: [1×1 struct] u738: [1×1 struct] u739: [1×1 struct] u740: [1×1 struct] u741: [1×1 struct] u742: [1×1 struct] u743: [1×1 struct] u744: [1×1 struct] u745: [1×1 struct] u746: [1×1 struct] u747: [1×1 struct] u748: [1×1 struct] u749: [1×1 struct] u750: [1×1 struct] u751: [1×1 struct] u752: [1×1 struct] u753: [1×1 struct] u754: [1×1 struct] u755: [1×1 struct] u756: [1×1 struct] u757: [1×1 struct] u758: [1×1 struct] u759: [1×1 struct] u760: [1×1 struct] u761: [1×1 struct] u762: [1×1 struct] u763: [1×1 struct] u764: [1×1 struct] u765: [1×1 struct] u766: [1×1 struct] u767: [1×1 struct] u768: [1×1 struct] u769: [1×1 struct] u770: [1×1 struct] u771: [1×1 struct] u772: [1×1 struct] u773: [1×1 struct] u774: [1×1 struct] u775: [1×1 struct] u776: [1×1 struct] u777: [1×1 struct] u778: [1×1 struct] u779: [1×1 struct] u780: [1×1 struct] u781: [1×1 struct] u782: [1×1 struct] u783: [1×1 struct] u784: [1×1 struct] u785: [1×1 struct] u786: [1×1 struct] u787: [1×1 struct] u788: [1×1 struct] u789: [1×1 struct] u790: [1×1 struct] u791: [1×1 struct] u792: [1×1 struct] u793: [1×1 struct] u794: [1×1 struct] u795: [1×1 struct] u796: [1×1 struct] u797: [1×1 struct] u798: [1×1 struct] u799: [1×1 struct] u800: [1×1 struct] u801: [1×1 struct] u802: [1×1 struct] u803: [1×1 struct] u804: [1×1 struct] u805: [1×1 struct] u806: [1×1 struct] u807: [1×1 struct] u808: [1×1 struct] u809: [1×1 struct] u810: [1×1 struct] u811: [1×1 struct] u812: [1×1 struct] u813: [1×1 struct] u814: [1×1 struct] u815: [1×1 struct] u816: [1×1 struct] u817: [1×1 struct] u818: [1×1 struct] u819: [1×1 struct] u820: [1×1 struct] u821: [1×1 struct] u822: [1×1 struct] u823: [1×1 struct] u824: [1×1 struct] u825: [1×1 struct] u826: [1×1 struct] u827: [1×1 struct] u828: [1×1 struct] u829: [1×1 struct] u830: [1×1 struct] u831: [1×1 struct] u832: [1×1 struct] u833: [1×1 struct] u834: [1×1 struct] u835: [1×1 struct] u836: [1×1 struct] u837: [1×1 struct] u838: [1×1 struct] u839: [1×1 struct] u840: [1×1 struct] u841: [1×1 struct] u842: [1×1 struct] u843: [1×1 struct] u844: [1×1 struct] u845: [1×1 struct] u846: [1×1 struct] u847: [1×1 struct] u848: [1×1 struct] u849: [1×1 struct] u850: [1×1 struct] u851: [1×1 struct] u852: [1×1 struct] u853: [1×1 struct] u854: [1×1 struct] u855: [1×1 struct] u856: [1×1 struct] u857: [1×1 struct] u858: [1×1 struct] u859: [1×1 struct] u860: [1×1 struct] u861: [1×1 struct] u862: [1×1 struct] u863: [1×1 struct] u864: [1×1 struct] u865: [1×1 struct] u866: [1×1 struct] u867: [1×1 struct] u868: [1×1 struct] u869: [1×1 struct] u870: [1×1 struct] u871: [1×1 struct] u872: [1×1 struct] u873: [1×1 struct] u874: [1×1 struct] u875: [1×1 struct] u876: [1×1 struct] u877: [1×1 struct] u878: [1×1 struct] u879: [1×1 struct] u880: [1×1 struct] u881: [1×1 struct] u882: [1×1 struct] u883: [1×1 struct] u884: [1×1 struct] u885: [1×1 struct] u886: [1×1 struct] u887: [1×1 struct] u888: [1×1 struct] u889: [1×1 struct] u890: [1×1 struct] u891: [1×1 struct] u892: [1×1 struct] u893: [1×1 struct] u894: [1×1 struct] u895: [1×1 struct] u896: [1×1 struct] u897: [1×1 struct] u898: [1×1 struct] u899: [1×1 struct] u900: [1×1 struct] u901: [1×1 struct] u902: [1×1 struct] u903: [1×1 struct] u904: [1×1 struct] u905: [1×1 struct] u906: [1×1 struct] u907: [1×1 struct] u908: [1×1 struct] u909: [1×1 struct] u910: [1×1 struct] u911: [1×1 struct] u912: [1×1 struct] u913: [1×1 struct] u914: [1×1 struct] u915: [1×1 struct] u916: [1×1 struct] u917: [1×1 struct] u918: [1×1 struct] u919: [1×1 struct] u920: [1×1 struct] u921: [1×1 struct] u922: [1×1 struct] u923: [1×1 struct] u924: [1×1 struct] u925: [1×1 struct] u926: [1×1 struct] u927: [1×1 struct] u928: [1×1 struct] u929: [1×1 struct] u930: [1×1 struct] u931: [1×1 struct] u932: [1×1 struct] u933: [1×1 struct] u934: [1×1 struct] u935: [1×1 struct] u936: [1×1 struct] u937: [1×1 struct] u938: [1×1 struct] u939: [1×1 struct] u940: [1×1 struct] u941: [1×1 struct] u942: [1×1 struct] u943: [1×1 struct] u944: [1×1 struct] u945: [1×1 struct] u946: [1×1 struct] u947: [1×1 struct] u948: [1×1 struct] u949: [1×1 struct] u950: [1×1 struct] u951: [1×1 struct] u952: [1×1 struct] u953: [1×1 struct] u954: [1×1 struct] u955: [1×1 struct] u956: [1×1 struct] u957: [1×1 struct] u958: [1×1 struct] u959: [1×1 struct] u960: [1×1 struct] u961: [1×1 struct] u962: [1×1 struct] u963: [1×1 struct] u964: [1×1 struct] u965: [1×1 struct] u966: [1×1 struct] u967: [1×1 struct] u968: [1×1 struct] u969: [1×1 struct] u970: [1×1 struct] u971: [1×1 struct] u972: [1×1 struct] u973: [1×1 struct] u974: [1×1 struct] u975: [1×1 struct] u976: [1×1 struct] u977: [1×1 struct] u978: [1×1 struct] u979: [1×1 struct] u980: [1×1 struct] u981: [1×1 struct] u982: [1×1 struct] u983: [1×1 struct] u984: [1×1 struct] u985: [1×1 struct] u986: [1×1 struct] u987: [1×1 struct] u988: [1×1 struct] u989: [1×1 struct] u990: [1×1 struct] u991: [1×1 struct] u992: [1×1 struct] u993: [1×1 struct] u994: [1×1 struct] u995: [1×1 struct] u996: [1×1 struct] u997: [1×1 struct] u998: [1×1 struct] u999: [1×1 struct] u1000: [1×1 struct]
S.u1
ans = struct with fields:
u: 0.1659
Features of this data that should be avoided if possible:
• Naming the variable the same as the filename. Avoid forcing lots of meta-data into the variable name: a much better (simpler, more reliable, more generalizable) approach is to store the meta-data in their own variables, e.g. in a variable named "position" or similar. Then your code will be simpler, more robust and easy to generalize.
• Lots and lots and lots of fields with pseudo-indices in their names. Replace awkward pseudo-indices with one array and actual indexing. Your code will be simpler, more robust, and much more efficient.
• Lots and lots and lots of scalar structures with one field each of which contains exactly one numeric scalar. Ouch!
Whenever meta-data is being forced into names of something then processing that data gets harder.
F = @(n)S.("u"+n);
A = [arrayfun(F, 1:numel(fieldnames(S))).u] % your data should be in an array
A = 1×1000
0.1659 0.1687 0.1745 0.1883 0.1867 0.1878 0.1904 0.2021 0.2060 0.2004 0.2044 0.2144 0.2264 0.2115 0.1913 0.1365 0.2197 0.1159 0.1076 0.1772 0.1478 0.1618 0.1716 0.1722 0.1652 0.1721 0.1789 0.1839 0.1959 0.1958

采纳的回答

Star Strider 2024-2-5

Perhaps —
LD = struct with fields:
U_at_right_top: [1×1 struct]
U = structfun(@(x)x.u, LD.U_at_right_top); % One Line
L = numel(U); % Vector Length
Fs = 30/2; % Estimated Sampling Freqeuency
t = linspace(0, L-1, L)/Fs; % Time Vector
figure
plot(t, U, '.-')
grid
xlabel('Time')
ylabel('U')
EDIT — (5 Feb 2024 at 13:45)
Changed ‘U’ assignment.
.
1 个评论显示 -1更早的评论隐藏 -1更早的评论
Stephen23 2024-2-5
Note that this assumes (but does not check) that the fieldnames are in alphanumeric order.

更多回答（2 个）

Rik 2024-2-5
Using numbered field names is a bad idea. It is almost as bad as using numbered variable names directly.
The solution is to use arrays. This could have been a struct array.
u = zeros(1,numel(fieldnames(U_at_right_top)));
for n=1:numel(u)
fnu=sprintf('u%d',n);
u(n) = U_at_right_top.(fnu).u;
end
plot(1:numel(u),u,'x--')
0 个评论显示 -2更早的评论隐藏 -2更早的评论

Jinal 2024-2-5
Hi hsnHkl
You can store your struct values in an array, 'u' and use the array to create a line plot outside the for loop.
I am attaching the code snippet for your reference.
n = 1000;
u = 0;
for j=1:n
fnu=sprintf('u%d',j);
u(j) = U_at_right_top.(fnu).u;
end
plot(u);
Attaching documentation of 2-D line plot for your reference.

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by